Google Play网络抓取:如何获得R中每个评论的票数?

我正在用R抓取Google Play应用的评论的网页,但得不到票数。我指示代码: 喜欢%html_nodes(“。xjKiLb”)%>%html_attr(“ aria-label”) ,但我没有任何价值。怎么办?

获得草稿

Google Play网络抓取:如何获得R中每个评论的票数?

完整代码

#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")

什么让我回来

  

NA NA NA

我想退回的物品

  

3 3 2

xwtangle007 回答:Google Play网络抓取:如何获得R中每个评论的票数?

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

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

enter image description here

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

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

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

本文链接:https://www.f2er.com/3144945.html

大家都在问