【问题标题】:How to perform web scraping to get all the reviews of the an app in Google Play?如何执行网络抓取以获取 Google Play 中应用程序的所有评论?
【发布时间】:2020-02-23 16:59:27
【问题描述】:

我假装能够获得用户在 Google Play 上留下的关于这些应用的所有评论。我有这个代码,他们在那里指出 Web scraping in R through Google playstore 。但问题是您只能获得前 40 条评论。有没有可能拿到app的所有cmet?

```

#Loading the rvest package
library(rvest)
library(magrittr) # for the '%>%' pipe symbols
library(RSelenium) # to get the loaded html of 

#Specifying the url for desired website to be scraped
url <- 'https://play.google.com/store/apps/details? 
id=com.phonegap.rxpal&hl=en_IN&showAllReviews=true'

# starting local RSelenium (this is the only way to start RSelenium that 
is working for me atm)
selCommand <- wdman::selenium(jvmargs = c("- 
Dwebdriver.chrome.verboseLogging=true"), retcommand = TRUE)
shell(selCommand, wait = FALSE, minimized = TRUE)
remDr <- remoteDriver(port = 4567L, browserName = "firefox")
remDr$open()

# go to website
remDr$navigate(url)

# get page source and save it as an html object with rvest
html_obj <- remDr$getPageSource(header = TRUE)[[1]] %>% read_html()

# 1) name field (assuming that with 'name' you refer to the name of the 
reviewer)
names <- html_obj %>% html_nodes(".kx8XBd .X43Kjb") %>% html_text()

# 2) How much star they got 
stars <- html_obj %>% html_nodes(".kx8XBd .nt2C1d [role='img']") %>% 
html_attr("aria-label")

# 3) review they wrote
reviews <- html_obj %>% html_nodes(".UD7Dzf") %>% html_text()

# create the df with all the info
review_data <- data.frame(names = names, stars = stars, reviews = reviews, 
stringsAsFactors = F)

```

【问题讨论】:

    标签: r selenium web-scraping google-play


    【解决方案1】:

    您可以从 GooglePlay 的网上商店获取所有评论。

    如果您滚动查看评论,您可以看到 XHR 请求被发送到:

    https://play.google.com/_/PlayStoreUi/data/batchexecute
    

    使用表单数据:

    f.req: [[["rYsCDe","[[\"com.playrix.homescapes\",7]]",null,"55"]]]
    at: AK6RGVZ3iNlrXreguWd7VvQCzkyn:1572317616250
    

    和参数:

    rpcids=rYsCDe
    f.sid=-3951426241423402754
    bl=boq_playuiserver_20191023.08_p0
    hl=en
    authuser=0
    soc-app=121
    soc-platform=1
    soc-device=1
    _reqid=839222
    rt=c
    

    玩弄了不同的参数,发现很多是可选的,请求可以简化为:

    表单数据:

    f.req: [[["UsvDTd","[null,null,[2, $sort,[$review_size,null,$page_token]],[$package_name,7]]",null,"generic"]]]
    

    参数:

    hl=$review_language
    

    响应是神秘的,但它本质上是带有键的 JSON 数据,类似于 protobuf,我为响应编写了一个解析器,将其转换为常规的 dict 对象。

    https://gist.github.com/xlrtx/af655f05700eb76bb29aec876493ed90

    【讨论】:

    • 使用您在 GitHub (gist.github.com/xlrtx/af655f05700eb76bb29aec876493ed90) 上编写的代码,我可以获得 Google Play 上的所有应用评论吗?我正在尝试执行您的代码,但“utils”包有问题。这返回给我:ModuleNotFoundError: No module named 'utils'
    • @DavidPerea 这是一个日志工具,你可以用'logging'模块替换它,确保它运行python 3.6或更高版本。该代码截至日期有效。
    • 我不明白为什么“utilis”模块对我不起作用。它是我必须事先安装的软件包还是我必须如何使它工作?我正在使用 Python 3.7。我搜索了许多论坛,看看为什么它出现在我身上:ModuleNotFoundError: No module named 'utils'。但我找不到解决方案。让我们看看您是否可以帮助我,我觉得能够获得所有 Google Play 评论非常有趣
    • utils 包是我写的一个实用模块,但是在这个 sn-p 中我只使用它的日志功能,所以我没有在代码中发布它。您可以使用 Python 默认的“日志记录”模块来替换它,或者直接使用“打印”功能。
    • 请原谅我对此事的无知。我更熟悉 R 而不是 Python,而且我很难应用代码。我不明白。我应该调用代码中的哪个类来获取应用程序的所有评论?我应该指出哪些参数?我需要你的帮助,因为我觉得能够得到它非常有趣。
    猜你喜欢
    • 2015-07-02
    • 2020-08-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 1970-01-01
    相关资源
    最近更新 更多