Я пытался заменить каждую строку, но не могу заставить ее работать. Я могу получить все данные между <span>...</span>
, но не могу, если он закрыт, как я могу это сделать? Я пытался заменить текст впоследствии, но я не могу это сделать. Я новичок в питоне.
Я также пытался использовать for x in soup.find_all('/span', class_ = "textLarge textWhite")
, но это ничего не отображает.
Соответствующий html:
<div style="width:100%; display:inline-block; position:relative; text-
align:center; border-top:thin solid #fff; background-image:linear-
gradient(#333,#000);">
<div style="width:100%; max-width:1400px; display:inline-block;
position:relative; text-align:left; padding:20px 15px 20px 15px;">
<a href="/manpower-fit-for-military-service.asp" title="Manpower
Fit for Military Service ranked by country">
<div class="smGraphContainer"><img class="noBorder"
src="/imgs/graph.gif" alt="Small graph icon"></div>
</a>
<span class="textLarge textWhite"><span
class="textBold">FIT-FOR-SERVICE:</span> 18,740,382</span>
</div>
<div class="blockSheen"></div>
</div>
Соответствующий код Python:
for y in soup.find_all('span', class_ = "textBold"):
print(y.text) #this gets FIT-FOR-SERVICE:
for x in soup.find_all('span', class_ = "textLarge textWhite"):
print(x.text) #this gets FIT-FOR-SERVICE: 18,740,382 but i only want the number
Ожидаемый результат : "18,740,382"