Problem
I want to download several Excel files from a website using R. I don't want to name each link separately, because there are many. I had a look at previous posts, but their links to the website did not work so I couldn't see how the answers related to the structure of the website.
The website I'm testing this on is: https://digital.nhs.uk/data-and-information/publications/statistical/adult-psychiatric-morbidity-survey/adult-psychiatric-morbidity-survey-survey-of-mental-health-and-wellbeing-england-2014
Attempt
My attempt to get the names of the full links for the attachments:
url <- "https://digital.nhs.uk/data-and-information/publications/statistical/adult-psychiatric-morbidity-survey/adult-psychiatric-morbidity-survey-survey-of-mental-health-and-wellbeing-england-2014"
simple <- read_html(url)
files <- simple %>%
html_nodes(".attachment") %>%
html_text()
Yet, whilst I can get the names of the files, I can't get the actual names of their links. In particular, I don't know how to get to the "a href" attribute. Once I get the names, then I'll work out how to download them using lapply and download.file.
Thanks everyone!
politely- it makes it easy to make sure that you're webscraping as respectfully as possible. Wouldn't want to burden the NHS! - Captain Hat