当前位置: 动力学知识库 > 问答 > 编程问答 >

r - RSelenium headless authentication download file

问题描述:

I would like to use this code with a headless browser (e.g. phantomjs or casperjs) and then download the csv file at the end (instead of the native browser's saver popup dialog).

library("RSelenium")

startServer()

mybrowser <- remoteDriver(browserName = 'chrome')

mybrowser$open()

mybrowser$navigate("http://steamspy.com/login/")

wxbox <- mybrowser$findElement(using = 'xpath', "//*/input[@name = 'username']")

wxbox$sendKeysToElement(list("myusername"))

wxbox <- mybrowser$findElement(using = 'xpath', "//*/input[@name = 'password']")

wxbox$sendKeysToElement(list("mypassword"))

wxbutton <- mybrowser$findElement(using = 'xpath', "//*/button[@name = 'submit']")

wxbutton$clickElement()

mybrowser$navigate("http://steamspy.com/sale.php?tagid=0&from=2015-04-01&to=2016-04-25&submit=")

wxbutton <- mybrowser$findElement(using = 'css selector', "#ToolTables_tablesales_0")

wxbutton$clickElement()

Simply by changing chrome with phantomjs leads to this following error at opening and navigating the page:

Error: Summary: UnknownError

Detail: An unknown server-side error occurred while processing the command.

class: org.openqa.selenium.UnsupportedCommandException

网友答案:

Install PhantomJS if you haven't done this: Go Here. Download the windows zip file and extract it;

Add the path to phantoms.exe which is usually in the extractedFolder\bin to the environment variable path by going to Control Panel -> System -> advanced system settings -> environment variables, and add the path to the PATH variable, ignore this if you know how to this already;

Restart your RStudio or R session;

Run the following:

library(RSelenium)
pJS <- phantom()
myBrowser <- remoteDriver(browserName = "phantomjs")
myBrowser$open()
分享给朋友:
您可能感兴趣的文章:
随机阅读: