我知道有几种方法可以从网上废弃数据,但是从这个网站上删除前100个电影列表的最不痛苦的方法是:https://editorial.rottentomatoes.com/guide/best-sci-fi-movies-of-all-time/
我想尽可能使用R并将结果存储为R文件。
非常感谢!
答案 0 :(得分:1)
library(rvest)
library(magrittr)
url <- paste0("https://editorial.rottentomatoes.com/guide/best-sci-fi-movies-of-all-time/", 1:7, "/")
all_titles <- character()
all_years <- numeric()
for (i in 1:length(url)) {
movies <- url[i] %>%
read_html() %>%
html_nodes(".article_movie_title")
titles <- movies %>%
html_nodes("a") %>%
html_text()
years <- movies %>%
html_nodes(".start-year") %>%
html_text()
all_titles <- c(all_titles, titles)
all_years <- c(all_years, years)
}
result <- data.frame(Titles = all_titles, Years = all_years)
print(result)