<li class="ft_lt">
<a href="javascript:void(0);" class="active">Properties<span itemprop="name">(64236)</span></a>
<li>
我想在(64236)
的span标签中获取信息,但是我只能访问Properties-word
iso_class = soup.select('.active')
for i in iso_class:
h.append(i.text)
print(h)
“属性”
但我希望(64236)
答案 0 :(得分:1)
您可以使用CSS attribute equals selector
iso_class = soup.select('span[itemprop="name"]')
答案 1 :(得分:1)
另一个选择:
from bs4 import BeautifulSoup
bsobj = BeautifulSoup(s, "lxml")
bsobj.find("span", {"itemprop":"name"}).text
答案 2 :(得分:1)
汤= bs4.BeautifulSoup(res.text,'lxml')
为我喝汤。find_all(“ a”,class _ =“ active”):
l =(i.find(“ span”,itemprop =“ name”)。text)
l = l.split(“)”)
l = int(l[0][1:])