r - 通过 Google Playstore 在 R 中进行网页抓取
问题描述
我想从谷歌游戏商店中抓取我想要的几个应用程序评论的数据。
名称字段
他们得了多少星
他们写的评论
#Loading the rvest package
library('rvest')
#Specifying the url for desired website to be scrapped
url <- 'https://play.google.com/store/apps/details?id=com.phonegap.rxpal&hl=en_IN'
#Reading the HTML code from the website
webpage <- read_html(url)
#Using CSS gradient_Selector to scrap the name section
Name_data_html <- html_nodes(webpage,'.kx8XBd .X43Kjb')
#Converting the Name data to text
Name_data <- html_text(Name_data_html)
#Look at the Name
head(Name_data)
但结果是
> head(Name_data)
character(0)
后来我尝试发现更多我发现 Name_data_html 有
> Name_data_html
{xml_nodeset (0)}
我是网络抓取的新手,可以帮助我解决这个问题!
解决方案
您应该使用 Xpaths 来选择网页上的对象:
#Loading the rvest package
library('rvest')
#Specifying the url for desired website to be scrapped
url <- 'https://play.google.com/store/apps/details?id=com.phonegap.rxpal&hl=en_IN'
#Reading the HTML code from the website
webpage <- read_html(url)
# Using Xpath
Name_data_html <- webpage %>% html_nodes(xpath='/html/body/div[1]/div[4]/c-wiz/div/div[2]/div/div[1]/div/c-wiz[1]/c-wiz[1]/div/div[2]/div/div[1]/c-wiz[1]/h1/span')
#Converting the Name data to text
Name_data <- html_text(Name_data_html)
#Look at the Name
head(Name_data)
看看如何获取这张图片中的路径:
推荐阅读
- apache-storm - 如何在 Storm Flux 中配置通用参数
- elixir - 选择合并在 Enum.reduce 中没有按预期工作
- amazon-web-services - 在 CloudFormation 模板中设置 T2Unlimited
- boomerang - 对数回旋镖参数
- python - 分析 BST 高度平衡
- php - 为什么 POST 被解释为 GET?
- c# - 为 ASP.NET Core 转换 Razor 项目
- wordpress - 我需要为所有用户显示 wordpress 插件“NS Cloner”,而不仅仅是网络管理员
- ios - UIApplication applicationState 只能在主线程中使用
- ruby-on-rails - 未初始化的常量 Admin::ModeratorsController::ModeratorInteractor