小编J.C*_*.C.的帖子

使用Rvest进行Web抓取-如果未找到节点,则返回NA。

我有点卡在这里。我想从网站上抓取数据,并提取一些内容,例如用户评分,评论等。我正在尝试将数据添加到数据框中。

下面是我到目前为止的代码:

# Read html and select the URLs for each game review. 

library(rvest)
library(dplyr)
library(plyr)

# Read the webpage and the number of ratings.

getGame <- function(metacritic_game) {

total_ratings<- metacritic_game %>%
  html_nodes("strong") %>%
  html_text()

total_ratings <- ifelse(length(total_ratings) == 0, NA, 
as.numeric(strsplit(total_ratings, " ") [[1]][1]))

# Get the game title and the platform.

game_title <- metacritic_game %>%
  html_nodes("h1") %>%
  html_text()

game_platform <- metacritic_game %>%
  html_nodes(".platform a") %>%
  html_text()

game_platform <- strsplit(game_platform," ")[[1]][57:58]
game_platform <- gsub("\n","", game_platform)
game_platform<- paste(game_platform[1], game_platform[2], sep …
Run Code Online (Sandbox Code Playgroud)

r rvest

3
推荐指数
1
解决办法
237
查看次数

标签 统计

r ×1

rvest ×1