如何获取/抓取游戏商店或应用程序商店中所有应用程序的评论,我刚刚获得前40条评论?

时间:2016-05-23 20:52:18

标签: python web-scraping google-play scrapy web-crawler

我正在使用python。 我将为应用程序播放商店网址,然后将正文解析为树,使用xpath

提取数据
reviews = parsed.xpath('//div[@class="single-review"]//div[@class="review-body with-review-wrapper"]')

然后在文件中删除它

reviewFile = rev.sub('[^A-Za-z0-9.,\' ]+', '', reviewFile.text_content().replace('  Full Review  ','').strip())
    print('writing reviewFile'+reviewFile)

但有了这个,我只能在谷歌游戏商店而不是所有评论中获得前40条评论。

在显示前40条评论后,Google Play开始通过ping http://play.google.com/store/getreviews

加载更多评论

1 个答案:

答案 0 :(得分:1)

您必须向https://play.google.com/store/getreviews发送帖子请求。帖子请求必须包含以下标题:

headers = {
  'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
}

您的查询(页面编号,评论排序等)应该是一个urlencoded字符串,如:

payload = 'reviewType=0&pageNum=' + pagenum + '&id=' + appid + '&reviewSortOrder=2&xhr=1'

然后,您可以使用请求模块发送此请求:

text = requests.post(url, data=payload, headers=headers).text

注意:响应实际上是一个列表的形式,里面有你需要解析的html,它有这个奇怪的)]}'的东西在开始时你将不得不摆脱。

相关问题