Home > Mobile >  How to extract only value "2"?
How to extract only value "2"?

Time:10-21

magic_number = soup.select_one('span:-soup-contains("people_alt")')

magic_number = soup.select_one('span:-soup-contains("people_alt")').text

magic_number = soup.select_one('span:-soup-contains("people_alt")').next_sibling

enter image description here

CodePudding user response:

Without any code as text and an url it is not that easy, so question needs improvement. Selecting more specific should work:

soup.select_one('.material-icons:-soup-contains("people_alt")').next_sibling.strip()

Example

from bs4 import BeautifulSoup

html = '''
<span>
<span >people_alt</span>
2
</span>

'''
soup = BeautifulSoup(html)

soup.select_one('.material-icons:-soup-contains("people_alt")').next_sibling.strip()

Output

2
  • Related