Created
April 26, 2017 21:17
-
-
Save PaulieGillett/c7daa503a001040c16b190f7025b5320 to your computer and use it in GitHub Desktop.
R: scrape multiple pages with XML and readHTMLTable
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(XML) | |
library(plyr) | |
base.url <- "http://www.ttmeiju.com/meiju/Movie.html?page" | |
GetTable <- function(page.number) { | |
full.url <- paste(base.url, page.number, sep = "=") | |
doc <- htmlParse(full.url, encoding = "GBK") | |
node <- getNodeSet(doc, "//table")[[2]] | |
last.row <- xmlSize(node) - 1 | |
table <- readHTMLTable(node, | |
header = TRUE, | |
skip.rows = c(1, last.row), | |
trim = TRUE, | |
stringsAsFactor = FALSE)} | |
ttm.tables <- ldply(1:10, GetTable, .progress = "text") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment