Google 玩网络抓取:如何在 R 中获取每条评论的投票数?

Google Play web scraping: how can you get the number of votes for each review in R?

我正在 R 中对 Google Play 应用的评论进行网络抓取,但我无法获得票数。我指出代码: likes <- html_obj %>% html_nodes(".xjKiLb") %>% html_attr("aria-label") 我没有得到任何价值。怎么做到的?

获得刮票

完整代码

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


url <- 'https://play.google.com/store/apps/details?id=com.gospace.parenteral&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()

likes <- html_obj %>% html_nodes(".xjKiLb") %>% html_attr("aria-label")

什么returns我

NA NA NA

我要退货的东西

3 3 2

也许您正在使用选择器小工具来获取 css 选择器。和你一样,我试过这样做,但是 css 选择器小工具 return 不正确。

检查页面的 html 代码,我意识到正确的元素包含在带有 class = "jUL89d y92BAb" 的标记中,正如您在此图片中所见。

这样,您应该使用的代码就是这个。

html_obj %>% html_nodes('.jUL89d') %>% html_text()

我个人的建议是始终检查源代码以确认选择器小工具的输出。