首页 > 解决方案 > Google Play 网页抓取:如何获得 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")

什么回报我

啦〜啦〜啦

我想要退回的东西

3 3 2

标签: rweb-scrapinggoogle-playrstudio

解决方案


也许您正在使用选择器小工具来获取 css 选择器。正如您一样,我尝试这样做,但是选择器小工具返回的 css 不是正确的。

检查页面的 html 代码,我意识到正确的元素包含在标签中,class = "jUL89d y92BAb"正如您在这张图片中看到的那样。

在此处输入图像描述

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

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

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


推荐阅读