简体   繁体   English

RSelenium 无头认证下载文件

[英]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).我想将此代码与无头浏览器(例如 phantomjs 或 casperjs)一起使用,然后在最后下载 csv 文件(而不是本机浏览器的保护程序弹出对话框)。

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:简单地通过使用phantomjs更改chrome会导致在打开和导航页面时出现以下错误:

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 .如果您还没有这样做,请安装 PhantomJS: Go Here Download the windows zip file and extract it;下载windows zip文件并解压;

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;进入控制面板 -> 系统 -> 高级系统设置 -> 环境变量,将phantoms.exe的路径添加到环境变量路径中,该路径通常在提取的文件夹\\bin中,并将路径添加到 PATH 变量中,如果你已经知道如何做到这一点了;

Restart your RStudio or R session;重启你的 RStudio 或 R 会话;

Run the following:运行以下命令:

library(RSelenium)
pJS <- phantom()
myBrowser <- remoteDriver(browserName = "phantomjs")
myBrowser$open()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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