Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Mac上从R中调用PhantomJS_Javascript_R_Phantomjs - Fatal编程技术网

Javascript 在Mac上从R中调用PhantomJS

Javascript 在Mac上从R中调用PhantomJS,javascript,r,phantomjs,Javascript,R,Phantomjs,我正在尝试获取一些用javascript呈现的数据。我想尝试使用phatomjs,但在R中调用phantomjs时遇到了一些问题 我下载了phatomjs,将文件放在我的工作目录中,并尝试运行找到的以下代码: 我做了一些搜索,这可能与我的路径有关,但我遵循了建议,它仍然抛出相同的错误 sudo ln -s /phantomjs-2.0.0-macosx/bin/phantomjs /usr/local/bin/ 知道为什么找不到phantomjs可执行文件吗 谢谢 会话信息: R versio

我正在尝试获取一些用javascript呈现的数据。我想尝试使用phatomjs,但在R中调用phantomjs时遇到了一些问题

我下载了phatomjs,将文件放在我的工作目录中,并尝试运行找到的以下代码:

我做了一些搜索,这可能与我的路径有关,但我遵循了建议,它仍然抛出相同的错误

sudo ln -s /phantomjs-2.0.0-macosx/bin/phantomjs /usr/local/bin/
知道为什么找不到phantomjs可执行文件吗

谢谢

会话信息:

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

不幸的是,64pix站点没有对数据使用XHR请求,而是填充主页上的“顶部”列表。如果您执行以下操作,则可以避免系统调用并留在-R中:

library(rvest)
library(V8)

url <- "http://64px.com/instagram/"
pg <- read_html(url)

script_data <- html_nodes(pg, "script")[[3]]
dat <- gsub("\\$\\(function.*$", "", html_text(script_data))

ctx <- v8()
ctx$eval(dat)
head(ctx$get("accounts"))
##        username followers followers_now
## 1     instagram  64131228      45251017
## 2  justinbieber  23817614      20279386
## 3 kimkardashian  23519002      22218039
## 4       beyonce  22207790      21375819
## 5  arianagrande  21748827      20219621
## 6   selenagomez  19572601      18456569
库(rvest)
图书馆(V8)

url您尝试过使用可执行文件的完整路径吗?@mrub我尝试过系统(“/phantomjs-2.0.0-macosx/bin/phantomjs scrap.js>scrap.html”),得到了相同的结果message@BillPetti我不知道Mac,但是作为根目录的phantomjs-2.0.0-macosx对我来说似乎是错误的。你确定这是完整的绝对路径吗?你试过先从终端运行phantomjs吗?@BillPetti,这是一个不同的问题。试着沿着这条路走。
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
library(rvest)
library(V8)

url <- "http://64px.com/instagram/"
pg <- read_html(url)

script_data <- html_nodes(pg, "script")[[3]]
dat <- gsub("\\$\\(function.*$", "", html_text(script_data))

ctx <- v8()
ctx$eval(dat)
head(ctx$get("accounts"))
##        username followers followers_now
## 1     instagram  64131228      45251017
## 2  justinbieber  23817614      20279386
## 3 kimkardashian  23519002      22218039
## 4       beyonce  22207790      21375819
## 5  arianagrande  21748827      20219621
## 6   selenagomez  19572601      18456569