r - 如何解决此网页抓取问题

标签 r rvest

我正在尝试在 R 中抓取网页。

page <- read_html("https://www.imdb.com/chart/top/") 
header_nodes <- html_nodes(page, css = ".titleColumn a" )
rating_nodes <- html_nodes(page, css = "strong")

我正在尝试提取电影标题和评级,但收到此错误:

Error in inDL(x, as.logical(local), as.logical(now), ...) : ICU init failed: U_FILE_ACCESS_ERROR

最佳答案

尝试使用这个:

library(rvest)
url <- 'https://www.imdb.com/chart/top/'
webpage <- url %>% read_html()

title <- webpage %>% html_nodes('td.titleColumn a') %>% html_text()
title

#[1] "The Shawshank Redemption"                                            
#[2] "The Godfather"                                                       
#[3] "The Godfather: Part II"                                              
#[4] "The Dark Knight"                                                     
#[5] "12 Angry Men"                                                        
#[6] "Schindler's List"                                                    
#[7] "The Lord of the Rings: The Return of the King"             
#...

获取评分:

ratings <- webpage %>% 
            html_nodes('td.ratingColumn strong') %>% 
            html_text() %>% as.numeric()
ratings
#[1] 9.2 9.1 9.0 9.0 8.9 8.9 8.9 .....

关于r - 如何解决此网页抓取问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61513918/

相关文章:

r - 下载 mp3 文件

r - 使用 r 导航和抓取带有下拉 html 表单的网页

Rvest 网络抓取返回空字符

r - 字符串列表到字符向量列表

r - 对于 R,安装 RMySQL 包时出错

r - 在公式中显示字符串,而不是在 lm fit 中显示为变量

r - lapply,c() 和 list() 的区别

r - 在 R 中使用 gsub 进行多项更改

r - 如何重命名包含 "(N)"的列名?

html - 使用 "rvest"抓取 html 表格