PhantomJS没有正确加载网页

时间:2016-10-31 10:52:22

标签: r phantomjs digital-ocean rselenium

使用RSelenium(来自CRAN的1.4.5)和PhantomJs(1.9.8)获取网站截图的以下R代码在AWS上的Mac OS和Ubuntu 14中运行良好。但是在Digital Ocean Ubuntu 14 Droplet上运行时,网页似乎无法正确加载。查看DigitalOceanAWS此网页的屏幕截图 - fantasy.premierleague.com/a/leagues/standings/1/classic。我使用RStudio来查看/保存图像。

library(RSelenium)
pJS <- phantom()
browser = remoteDriver(browserName = "phantomJS")
browser$open()
url <- 'https://fantasy.premierleague.com/a/leagues/standings/1/classic'
browser$navigate(url)
browser$screenshot(display = TRUE)
pJS$stop()

我在Ubuntu上安装了如下的PhantomJS和RSelenium:

#Install/Update system software
sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
#Install packages dependencies
sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libfontconfig1 libfontconfig1-dev
#Download PhantomJS
cd ~
export PHANTOM_JS="phantomjs-2.1.1-linux-x86_64"
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2
#Move PhantomJS to /usr/local/share/ and create a symlink:
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
#Install pre-requisites for RSelenium
sudo apt-get install r-cran-xml
sudo apt-get install r-cran-RCurl

这可能是什么问题?在DigitalOcean上有解决此问题的方法吗?

1 个答案:

答案 0 :(得分:0)

我在ubuntu 16.04上看到了同样的问题,但在Windows上看不到。

我还在ubuntu 16.04上看到以下输出:

> browser$navigate(url)
[ERROR - 2016-10-31T13:04:20.726Z] Session [89254650-9f6a-11e6-b112-2f925adde426] - page.onError - msg: ReferenceError: Can't find variable: $

  phantomjs://platform/console++.js:263 in error
[ERROR - 2016-10-31T13:04:20.726Z] Session [89254650-9f6a-11e6-b112-2f925adde426] - page.onError - stack:
  global code (https://fantasy.premierleague.com/a/leagues/standings/1/classic:5988)

  phantomjs://platform/console++.js:263 in error

谷歌搜索错误似乎是phantomjs / ghostdriver的当前问题。有一个新版本的phantomjs / ghostdriver 希望很快就会降落。我发现无视SSL错误对我有用:

library(RSelenium)
pJS <- phantom(extras = "--ignore-ssl-errors=true")
browser = remoteDriver(browserName = "phantom")
browser$open()
url <- 'https://fantasy.premierleague.com/a/leagues/standings/1/classic'
browser$navigate(url)
browser$screenshot(display = TRUE)
pJS$stop()