python - 刮板不从动态网页返回结果
问题描述
我正在尝试从https://store.steampowered.com/newshub/app/1145360抓取所有更新说明。我用“eventcalendar_CalendarRow_398u2”类标识了更新说明,并编写了如下代码:
updatenotes = soup.find_all("div", attrs={"class":"eventcalendar_CalendarRow_398u2"})
for updatenote in updatenotes:
但是当我尝试抓取时,它不会返回任何结果,我认为这是由于网站的动态特性。在开始抓取之前,我正在使用 Selenium 完全向下滚动,但它不起作用。有人能帮忙吗?
解决方案
尝试以下
driver.get('https://store.steampowered.com/newshub/app/1145360')
scroll_pause_time = 1
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
updatenotes=driver.find_elements_by_css_selector("div.eventcalendar_CalendarRow_398u2")
print(len(updatenotes))
for updatenote in updatenotes:
print(updatenote.text)
# Scroll down to bottom
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
time.sleep(scroll_pause_time)
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
# If heights are the same it will exit the function
break
last_height = new_height
推荐阅读
- javascript - 我必须映射一个组合数组
- vba - 用当前时间更新表字段
- java - 使用递归查找从根节点到树中指定节点的路径
- matlab - :Inf x 1 除以 :Inf x 1 得到 :Inf x :Inf Matlab
- c# - 从列表中获取具有最大日期的记录
- git - Git 在合并 A->B 然后 B->A 时不会产生新的提交,我如何确保其他团队看到第二次合并?
- react-native - ReactNative - 构建失败:http://central.maven.org/maven2/com/facebook/react/react-native/maven-metadata.xml'。需要 501 HTTPS
- pdf - 如何在保持透明度的同时从 Linux 中的 PDF 中提取图像?
- c++ - it gives me expected identifier before { token
- mysql - MYSQL - 如何修复不使用索引的慢查询,如何加快响应时间?