【发布时间】:2020-09-30 08:58:14
【问题描述】:
我正在尝试在 PlayStore 上公开获得一些评论数据,并且由于提供的 API 只允许获取自己的应用程序的评论,我正在尝试从网络上抓取它。
我正在使用 requests 包来获取 PlayStore 上给定应用程序的 HTML 页面,并将使用 BeautifulSoup 对其进行解析并将其保存到文件中,然后提取相关内容(每个用户的评分和评论)。
我的问题是使用request.get(URL) 检索的不是页面的全部内容。
导航到 PlayStore 上应用程序的“阅读所有评论”,您会进入包含该应用程序所有评论的页面。不幸的是,第一次加载页面时只有有限的评论集加载,而其余评论仅在向下滚动到底部时加载。通过调用 request.get(URL) 仅检索有限的评论集,而不是所有评论。
尝试导航到https://play.google.com/store/apps/details?id=com.bendingspoons.thirtydayfitness&hl=en&showAllReviews=true,只有在滚动到页面底部时才会加载较早的评论。
有没有办法访问整个页面/触发加载更多评论/模拟滚动?
下面是我的代码:
# get reviews for Thirty Days of Fitness app
URL = "https://play.google.com/store/apps/details?id=com.bendingspoons.thirtydayfitness&hl=en&showAllReviews=true"
# make request
request = requests.get(URL)
# extract HTML text
raw_text = request.text
# parse HTML and prettify
soup = BeautifulSoup(raw_text, 'html.parser')
text = soup.prettify()
# write to file
save_path = './thirtydayfitness_html.txt'
with open(save_path, 'w+', encoding=request.encoding) as f:
f.write(text)
【问题讨论】:
标签: python html python-3.x web web-scraping