Last active
August 29, 2015 14:16
-
-
Save pbiecek/3e90e42651e3160b7abe to your computer and use it in GitHub Desktop.
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
library(rvest) | |
library(PogromcyDanych) | |
serialsToParse <- levels(serialeIMDB$imdbId) | |
# prepare matrix for results | |
ratingsGroup <- matrix("", length(serialsToParse), 14) | |
rownames(ratingsGroup) <- serialsToParse | |
colnames(ratingsGroup) <- c("Males", "Females", "Aged under 18", "Males under 18", | |
"Females under 18", "Aged 18-29", "Males Aged 18-29", "Females Aged 18-29", | |
"Aged 30-44", "Males Aged 30-44", "Females Aged 30-44", "Aged 45+", | |
"Males Aged 45+", "Females Aged 45+") | |
# for all series | |
for (serial in serialsToParse) { | |
page <- html(paste0("http://www.imdb.com/title/",serial,"/ratings")) | |
nodes3 <- html_nodes(page, "table:nth-child(11) td:nth-child(3)") | |
ratingsGroup[serial,] <- gsub(html_text(nodes3)[-1], pattern="[^0-9\\.]", replacement="")[1:14] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment