问题
I am using R R 3.1.1 on OS X Yosemite(10.10.4). I have recently installed RSelenium and I constantly receive an unknown error. The code that I use is as follow:
require(RSelenium)
checkForServer()
startServer()
Sys.sleep(5)
remDr <- remoteDriver()
remDr$open()
The error is as follows:
remDr$open() [1] "Connecting to remote server" Undefined error in RCurl call. Error in queryRD(paste0(serverURL, "/session"), "POST", qdata = toJSON(serverOpts)) :
I tried downloading the selenium-java-2.41.0 from the official website. Then I put the file in the Library/Java/Extension. Then I tried this line of code
system("java -jar ~/Library/Java/Extension/selenium-2.47-2.1/selenium-java-2.47.1.jar")
But it did not worked and I kept on receiving the same error.
Then I used the terminal to install the package like this:
sudo java -jar selenium-server-standalone-2.47.1.jar
It installed something but still the problem did not solved. I have no idea what else to do.
回答1:
It's a security issue for Mac's. You need to download the standalone selenium server from http://www.seleniumhq.org/download/, put it in the same directory as the script you are trying to run, then run it. Your security settings might prevent this because it's "not authenticated," which means you'll have to go to your security settings and manually override. After that, it'll work fine.
Source:
http://www.computerworld.com/article/2971265/application-development/how-to-drive-a-web-browser-with-r-and-rselenium.html
回答2:
I don't know if you are still interested, but I struggled with this for days! Here is what works for my installation (RSelenium 1.3.5, phantom for Mac OS X 2.0.0, R 3.2.2, OS X Yosemite 10.10.4):
library("RSelenium")
message("Starting Phantom JS ...")
pJS <- phantom() # starts PhantomJS in webdriver mode on port 4444
Sys.sleep(5) # give binary time to run and open port
eCap <- list(phantomjs.page.settings.userAgent
= "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36")
remDr <- remoteDriver(browserName = "phantomjs", extraCapabilities = eCap)
message("Opening headless browser session ...")
remDr$open(silent=T)
Sys.sleep(5) # give it a moment
Phantom is in the usr/bin/ directory. Notice there is no "startServer()" statement or finding the selenium jar and running it. If you run the Selenium server directly it opens port 4444, and then Phantom JS will not start on that port. Use the command "lsof -i :4444" in the Mac terminal window to see what is happening on port 4444.
Having done all this, the operation is still not satisfactory - I can only execute a handful of RSelenium commands before I get the spinning color wheel and have to go to the terminal window and issue a "kill PID" command to get control of R again. I have tried putting in delays all over the place in case the problem is slow website response time, but it doesn't make any difference.
Good luck.
来源:https://stackoverflow.com/questions/31948860/rselenium-in-mac