Python Scraper未从动态网页返回结果
我正试图从中删除所有更新笔记。我用类“eventcalendar\u CalendarRow\u 398u2”标识更新注释,并编写如下代码:Python Scraper未从动态网页返回结果,python,selenium,beautifulsoup,steam,scrape,Python,Selenium,Beautifulsoup,Steam,Scrape,我正试图从中删除所有更新笔记。我用类“eventcalendar\u CalendarRow\u 398u2”标识更新注释,并编写如下代码: updatenotes = soup.find_all("div", attrs={"class":"eventcalendar_CalendarRow_398u2"}) for updatenote in updatenotes: 但是,当我尝试刮,它不会返回任何结果,我认为这是由于网站的动态
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
谢谢,这很酷,但是当我试图从一个有很多条目的页面(对于其他游戏)中抓取时,它只返回页面底部的值,而不是整个页面。我认为在页面上滚动有点笨拙,也许这就是问题所在。有什么想法吗?好的,试试这个。这是滚动到底部的代码,对吗?问题是,一旦你向下滚动到底部,然后进行刮取,代码只会刮取页面底部的数据,而不会刮取网站顶部的数据。如果我不滚动,我只会从顶部获取数据。所以基本上刮板只能刮屏幕附近的东西,这很奇怪。