Webscraping with R

I'm trying to create a script to download xlsx files from a website. The code below already downloads a file, but I need to change a specific parameter on the website by clicking a button.
When I log into the website using a browser the parameter is set to 176 (setIdPlantaAtual(176)), so the downloaded file corresponds to information from source 176.
What I need to do is to change this parameter simulating a button click to set this parameter to a different source.
Example: onclick="setIdPlantaAtual(275)". This is part of website's HTML.

What should I do to make this work?


url <- "https://genericwebsite.com/auth/login?redirectUrl="
download_url <- "https://genericwebsite.com/petpro/pets/generaterexcel.xlsx"
session <- html_session(url)
form <- html_form(session)[[1]]

filled_form <- set_values(form,
                          email = "myemail@myemail.com"
                          senha = "mypassword")

## Save main page url
main_page <- submit_form(session, filled_form)

#after login and submit_form do this:
download <- jump_to(main_page, download_url)

# write file to current working directory
writeBin(download$response$content, basename(download_url))

Can you provide an example that doesn't require authentication to fix the regexp?

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.