I am trying to scrape some data that is rendered with javascript. I wanted to try and go the phatomjs route, but am running into some issues invoking phantomjs from within R.
I downloaded phatomjs, placed the file in my working directory, and tried to run the following code found here:
library(rvest)
url <- "http://64px.com/instagram/"
# write out a script phantomjs can process
writeLines(sprintf("var page = require('webpage').create();
page.open('%s', function () {
console.log(page.content); //page source
phantom.exit();
});", url), con="scrape.js")
# process it with phantomjs
system("phantomjs scrape.js > scrape.html")
The last command generates this error:
sh: phantomjs: command not found
I did some searching and it may have to do with my PATH, but I followed the advice here and it still throws the same error.
sudo ln -s /phantomjs-2.0.0-macosx/bin/phantomjs /usr/local/bin/
Any idea why it's not finding the phantomjs executable?
Thanks.
Session Info:
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.2 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggvis_0.4.2 knitr_1.11 dplyr_0.4.3 plyr_1.8.3 stringr_1.0.0 rvest_0.2.0
[7] magrittr_1.5 RSelenium_1.3.5 XML_3.98-1.3 RJSONIO_1.3-0 RCurl_1.95-4.7 bitops_1.0-6
[13] pacman_0.3.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.1 xtable_1.7-4 R6_2.1.1 httr_1.0.0 highr_0.5 caTools_1.17.1
[7] tools_3.2.2 parallel_3.2.2 DBI_0.3.1 htmltools_0.2.6 assertthat_0.1 digest_0.6.8
[13] shiny_0.12.2 formatR_1.2 mime_0.3 evaluate_0.7.2 stringi_0.5-5 httpuv_1.3.3