gpt4 book ai didi

用于 "save link as"的 Rselenium 命令

转载 作者:行者123 更新时间:2023-12-04 11:39:48 25 4
gpt4 key购买 nike

(警告,新手,慢慢学习R)

你好呀,

我正在尝试使用 R 从网站自动下载数据。该网站正在使用 sharepoint,在询问 (R download from aspx in https getting website instead of CSV) 后,有人将我指向 RSelenium。

我需要的是从这样的地址下载 csv 文件:
https://www.paoilandgasreporting.state.pa.us/publicreports/Modules/Production/ProductionByCountyExport.aspx?UNCONVENTIONAL_ONLY=false&INC_HOME_USE_WELLS=true&INC_NON_PRODUCING_WELLS=true&PERIOD=15AUGU&COUNTY=ALLEGHENY

但在我需要接受协议(protocol)之前(我正在使用 RSelenium 进行“点击”)代码在这里:

# Using RSelenium to save file
##Installing the package if needed
install.packages("RSelenium")
##Activating
library("RSelenium")
checkForServer()
startServer()
#I had to start the server manually!
remDr <- remoteDriver()
remDr
remDr$open()
#open website and accepting conditions
remDr$navigate("https://www.paoilandgasreporting.state.pa.us/publicreports/Modules/Welcome/Agreement.aspx")
AgreeButton<-remDr$findElement(using = 'id', value="MainContent_AgreeButton")
AgreeButton$highlightElement()
AgreeButton$clickElement()

remDr$navigate("https://www.paoilandgasreporting.state.pa.us/publicreports/Modules/Production/ProductionByCountyExport.aspx?UNCONVENTIONAL_ONLY=false&INC_HOME_USE_WELLS=true&INC_NON_PRODUCING_WELLS=true&PERIOD=15AUGU&COUNTY=ALLEGHENY")

我的问题是:
我在 RSelenium 中找不到“将链接另存为”的命令

我想我需要找到这种类型的东西:
CSVurl<-remDr$navigate ("https://www.paoilandgasreporting.state.pa.us/publicreports/Modules/Production/ProductionByCountyExport.aspx?UNCONVENTIONAL_ONLY=false&INC_HOME_USE_WELLS=true&INC_NON_PRODUCING_WELLS=true&PERIOD=15AUGU&COUNTY=ALLEGHENY")remDr$navigate("https://www.paoilandgasreporting.state.pa.us/publicreports/Modules/Production/ProductionByCountyExport.aspx?UNCONVENTIONAL_ONLY=false&INC_HOME_USE_WELLS=true&INC_NON_PRODUCING_WELLS=true&PERIOD=15AUGU&COUNTY=ALLEGHENY")

CSVurl$saveLinkAs(fileName)

这存在吗?
在 R 中有更好的方法来做到这一点吗?

提前致谢

最佳答案

`# Using RSelenium to save file
##Installing the package if needed

##Activating
library(RSelenium)
checkForServer()
startServer()
#I had to start the server manually!

cprof<-makeFirefoxProfile(list(
"browser.helperApps.neverAsk.saveToDisk"='text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream',
"browser.helperApps.neverAsk.openFile"='text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream'

))
remDr <- remoteDriver(extraCapabilities=cprof)
remDr$open()
#open website and accepting conditions
remDr$navigate("https://www.paoilandgasreporting.state.pa.us/publicreports/Modules/Welcome/Agreement.aspx")
AgreeButton<-remDr$findElement(using = 'id', value="MainContent_AgreeButton")
AgreeButton$highlightElement()
AgreeButton$clickElement()

remDr$navigate("https://www.paoilandgasreporting.state.pa.us/publicreports/Modules/Production/ProductionByCountyExport.aspx?UNCONVENTIONAL_ONLY=false&INC_HOME_USE_WELLS=true&INC_NON_PRODUCING_WELLS=true&PERIOD=15AUGU&COUNTY=ALLEGHENY")`

要访问该文件,您必须搜索 firefox 的默认下载文件夹。

如果您收到错误消息说 R 无法创建 cprof 或无法压缩内容,那么您可能需要安装 RTools。

来自 here

检查您已安装的 R 的确切版本。

希望这可以帮助。

关于用于 "save link as"的 Rselenium 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33683790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com