尝试从a标签内的span元素中抓取文本

时间:2019-03-31 15:20:05

标签: html beautifulsoup

<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)

3 个答案:

答案 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:])