I'm looking for help downloading a .csv
file at a site that requires a login. I have no issues with the code that gets me to login. It works, because I'm able to scrape HTML at the website behind the login.
Here's the code I use to login:
login_baseballhq <- function(bbhq_id = Sys.getenv("bbhq_id"),
bbhq_password = Sys.getenv("bbhq_password")) {
# Open Session on Base Login Page
my_session <- rvest::html_session("https://www.baseballhq.com")
unfilled_forms <- rvest::html_form(my_session)
login_form <- unfilled_forms[[1]]
filled_form <- rvest::set_values(login_form, name = bbhq_id, pass = bbhq_password) # fill the form
login_session <- rvest::submit_form(my_session, filled_form)
return(login_session)
}
Code used to scrape HTML
url <- "https://www.baseballhq.com/members/tools/stat_proj?lg=M&p=B&t=P"
# Get Page Session Function?
page <- rvest::jump_to(login_session, url)
page <-
page %>%
xml2::read_html()
How do I go about downloading a .csv
file at the site? The URL I click to get the file is "https://www.baseballhq.com/download_stats.php?file=M_B_P".
When I copy and paste the link to a new browser tab I get the following message.
Please login to BaseballHQ.Com before attempting to download a file.