简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM