我正在尝试抓取IMDB数据,对于一个变量,我一直收到错误。
错误:结果28不是长度为1的原子矢量
library(rvest)
library(purrr)
library(tidyr)
topmovies <- read_html("http://www.imdb.com/chart/top")
links <- topmovies %>%
html_nodes(".titleColumn") %>%
html_nodes("a") %>%
html_attr("href") %>%
xml2::url_absolute("http://imdb.com")
pages <- links %>% map(read_html)
budget <- try(pages %>%
map_chr(. %>%
html_nodes("#titleDetails .txt-block:nth-child(11)") %>%
html_text() %>%
#gsub("\\D", "", .) %>%
extract_numeric()),silent=TRUE)
当我尝试使用(如代码中)时,我得到了
budget
[1]&#34;错误:无法将对象转换为数据帧\ n&#34; ATTR(&#34;类&#34) [1]&#34;尝试错误&#34; attr(,&#34; condition&#34;)
如果有人能告诉我出了什么问题/为什么试着不跳过那个结果会很棒?谢谢!
答案 0 :(得分:0)
遇到NULL
时会发生这种情况。尝试:
map_if(is_empty, ~ NA_character_)
管道链中的,看它是否有效。