Rselenium team for "save link as"

(warning, newbie, slowly learning R)

Hello,

I try to download data automatically from a website using R. The website uses sharepoint and after the request ( R download from aspx to https, getting the site instead of CSV ) someone pointed me to RSelenium.

I need to download csv files from the following URLs: https://www.paoilandgasreporting.state.pa.us/publicreports/Modules/Production/ProductionByCountyExport.aspx?UNCONVENTIONAL_ONLY=false&INC_HOME_USE_WELLS=true&INC_NELLUTELODElEIleTerlEngleDElEnElElEDerDElEnElEDerDer and NeUrlEDOlEngElEdEngElEdEngElEngElEngElEd

But before I need to accept the agreement (a "click" I do with RSelenium) The code is here:

# 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?

+4
1
`# 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.

R.

, .

+1

Source: https://habr.com/ru/post/1615669/


All Articles