<li class="ft_lt">
<a href="javascript:void(0);" class="active">Properties<span itemprop="name">(64236)</span></a>
<li>

I want to get the info in the span tag that is (64236) but I am able to access only the Properties-word

iso_class = soup.select('.active')

for i in iso_class:
    h.append(i.text)

print(h)

'Properties'

but I expect (64236)

3 Answers

1
Pranav C Balan On

You can use CSS attribute equals selector

iso_class = soup.select('span[itemprop="name"]')
1
sentence On

Another option:

from bs4 import BeautifulSoup

bsobj = BeautifulSoup(s, "lxml")
bsobj.find("span", {"itemprop":"name"}).text
1
rohit On

soup = bs4.BeautifulSoup(res.text, 'lxml')
for i in soup.find_all("a", class_="active"):
l = (i.find("span", itemprop="name").text)
l = l.split(")")

    l = int(l[0][1:])