Created
December 21, 2015 20:03
-
-
Save thirdwing/7a0bf107cad6f7f41927 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
require(RCurl) | |
require(XML) | |
webpage <- getURL("https://en.wikipedia.org/wiki/N-gram") | |
webpage <- readLines(tc <- textConnection(webpage)); close(tc) | |
pagetree <- htmlTreeParse(webpage, error=function(...){}, useInternalNodes = TRUE) | |
x <- xpathSApply(pagetree, "//*/p", xmlValue) | |
x <- unlist(strsplit(x, "\n")) | |
x <- gsub("\t","",x) | |
x <- sub("^[[:space:]]*(.*?)[[:space:]]*$", "\\1", x, perl=TRUE) | |
x <- x[!(x %in% c("", "|"))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment