在Python的HTML标记内查找特定文本

问题描述 投票:0回答:1

我已经尝试了100万种方法来解析热情,但尚未成功。

这里是带有zestimate信息的html标签:

<span>
  <span tabindex="0" role="button">
    <span class="sc-bGbJRg iiEDXU ds-dashed-underline">
      Zestimate
    <sup>®</sup>
    </span>
  </span>
  :&nbsp;
  <span>$331,425</span>
</span>

老实说,我以为这会让我接近,但我得到了一个空名单:

link = 'https://www.zillow.com/homedetails/1404-Clearwing-Cir-Georgetown-TX-78626/121721750_zpid/'
searched_word = '<span class="sc-bGbJRg iiEDXU ds-dashed-underline">Zestimate<sup>®</sup></span>'
test_page = requests.Session().get(link, headers=req_headers)
test_soup = BeautifulSoup(test_page.content, 'lxml')
results = test_soup('span',string='searched_word')
print(results)[0]
python beautifulsoup html-parsing
1个回答
0
投票

要从网站上获取正确的HTML,请添加User-Agent标头以进行请求。

例如:

© www.soinside.com 2019 - 2024. All rights reserved.