I want to download a file using webdriver package (phantomJS), however whenever I click/enter the object, nothing happens. I intend to click on 'Download dos dados' and then click and download 'Baixar .csv'.
library(webdriver)
url <-'https://idesevis.dee.rs.gov.br/#tab-9023-6'
#webdriver::install_phantomjs() # If it is not installed
pjs <- run_phantomjs()
ses <- Session$new(port = pjs$port)
ses$go(url)
ses$getUrl()
### Click on 'Download dos dados'
search <- ses$findElement(xpath='/html/body/div[2]/nav/div/ul/li[6]/a')
search$sendKeys('html',key$enter)
### Finds and clicks 'Baixar .csv'
search <- ses$findElement(xpath='/html/body/div[2]/div[3]/div/div[7]/div/div[1]/form/a')
search$sendKeys('html',key$enter)
ses$takeScreenshot()
Apparently, I'm not selecting the object 'Baixar .csv' even using the full xpath. I'm using webdriver as I can't use RSelenium on my notebook and static webscraping it is not suitable here as the session code alters everytime we access the main url.
CSV download, at least in this particular case with Shiny-driven page, also works outside of the browser session, so instead of triggering download in PhantomJS, you could extract href from CSV link and pass it to
download.file()/httr(2)/curl, for example.Downloaded dataset:
Created on 2023-12-27 with reprex v2.0.2