-
-
Save toyeiei/d1188399b0bee6acc68e3fcf345393c3 to your computer and use it in GitHub Desktop.
rvest final tutorial 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# select movie name | |
imdb %>% | |
html_nodes(".lister-item-header a") %>% | |
html_text() -> movie_names | |
# select year | |
imdb %>% | |
html_nodes(".text-muted.unbold") %>% | |
html_text() %>% | |
# extract numeric year | |
stringr::str_extract('[0-9]+') %>% | |
as.integer() -> years | |
# select rating | |
imdb %>% | |
html_nodes(".ratings-imdb-rating strong") %>% | |
html_text() %>% | |
as.numeric() -> ratings | |
# create dataframe | |
imdb_data <- data.frame(movie_names, years, ratings) | |
# export csv file | |
write.csv(imdb_data, "imdb_data.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment