简体   繁体   中英

RSelenium headless authentication download file

I would like to use this code with a headless browser (eg 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM