Petr Petrov
Petr Petrov

Reputation: 4452

BeautifulSoup: get text from some tag

I have data

<span class="label">Привод:</span> передний<br/>
<span class="label">Тип кузова:</span> седан<br/>
<span class="label">Цвет:</span> серый<br/>
<span class="label">Пробег по России:</span> есть<br/>
<span class="label">Пробег, км:</span> 87000<br/>
<span class="label">Руль:</span> левый<br/>

I need to get 87000 I try

mileage = soup.find('span', class_='label', text='Пробег, км:').findNext('br').get_text()

or

mileage = soup.find('span', class_='label', text='Пробег, км:').next_subling

but it returns None. What I do wrong?

Upvotes: 0

Views: 110

Answers (1)

alecxe
alecxe

Reputation: 474151

In the first code snippet, you are trying to get the text of the br element but it does not have any.

In the second code snippet you have a typo - it is not next_subling, it is next_sibling:

soup.find('span', class_='label', text='Пробег, км:').next_sibling

Upvotes: 3

Related Questions