-
-
Save mathiasfls/52a6784c3bd4bf67272ee1e2c1d4e634 to your computer and use it in GitHub Desktop.
V8 cheerio rvest example
This file contains hidden or 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
| # Proof of concept of using V8 to parse HTML in R | |
| # Example taken from rvest readme | |
| # Jeroen Ooms, 2015 | |
| library(V8) | |
| stopifnot(packageVersion("V8") >= "0.4") | |
| # Get Document | |
| html <- paste(readLines("http://www.imdb.com/title/tt1490017/"), collapse="\n") | |
| # Initiate Cheerio | |
| ct <- new_context() | |
| ct$source("https://raw.githubusercontent.com/jeroenooms/js/master/inst/lib/cheerio.min.js") | |
| # Parse HTML | |
| ct$assign('html', html) | |
| ct$assign('lego_movie', I('cheerio.load(html)')) | |
| ct$get('lego_movie("strong span").text()') | |
| # Play around some more: | |
| ct$console() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment