【发布时间】:2021-03-20 10:44:36
【问题描述】:
我正在尝试从 Zillow 的图表中删除数字和日期。 网址为:https://www.zillow.com/austin-tx/home-values/
我正在使用的 html 中的区域是:
<ul class="legend-entries" id="yui_3_18_1_1_1607476788112_1009">
<li class="legend-value">Oct 2021</li>
<li class="legend-entry legend-entry-0" id="yui_3_18_1_1_1607476788112_1330">Austin $464K</li>
<li class="hide legend-entry legend-entry-1"></li>
<li class="hide legend-entry legend-entry-2"></li>
<li class="hide legend-entry legend-entry-3"></li>
<li class="hide legend-entry legend-entry-4"></li>
<li class="hide legend-entry legend-entry-5"></li>
<li class="hide legend-entry legend-entry-6"></li>
</ul>
我正在尝试解析 legend-value(2021 年 10 月)和 legend-entry($464K)文本。但是,当您将鼠标悬停在图表上的点上(页面上存在此数据的位置)时,每当您移动鼠标时,html 中的值都会发生变化。
到目前为止,这是我的代码:
from bs4 import BeautifulSoup
req_headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.8',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
all_data = []
url = 'https://www.zillow.com/austin-tx/home-values/'
r = s.get(url, headers=req_headers)
soup = BeautifulSoup(r.content, 'html.parser')
#soup.find (class_= 'legend-entries')
for ul in soup.find_all('ul'):
lis=ul.find_all('li')
for elem in lis:
all_data.append(elem.text.strip())
我觉得这应该可以工作,但它什么也没返回。我的代码中的散列行将至少返回 legend-entries 标记。我不确定如何实现这一点。
【问题讨论】:
-
这是由 javascript 生成的。您的预期输出是什么?
标签: python beautifulsoup html-parsing