我正在尝试在 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/