title: R code for downloading all the pdfs given on a site: Web scraping
body: <p>I want to code in R which can download all the pdfs given on this URL: <a href="https://www.rbi.org.in/scripts/AnnualPublications.aspx?head=Handbook%20of%20Statistics%20on%20Indian%20Economy" rel="nofollow noreferrer">https://www.rbi.org.in/scripts/AnnualPublications.aspx?head=Handbook%20of%20Statistics%20on%20Indian%20Economy</a>
  and then download all the pdfs in a folder. I tried the following code with the help of <a href="https://towardsdatascience.com" rel="nofollow noreferrer">https://towardsdatascience.com</a> but the code is erroring out as</p>
  <pre><code>library(tidyverse)
  library(rvest)
  library(stringr)
  library(purrr)
  page &lt;- read_html(&quot;https://www.rbi.org.in/scripts/AnnualPublications.aspx? 
  head=Handbook%20of%20Statistics%20on%20Indian%20Economy&quot;) %&gt;%
  
  raw_list &lt;- page %&gt;% # takes the page above for which we've read the html
  html_nodes(&quot;a&quot;) %&gt;%  # find all links in the page
  html_attr(&quot;href&quot;) %&gt;% # get the url for these links
  str_subset(&quot;\\.pdf&quot;) %&gt;% # find those that end in pdf only
  str_c(&quot;https://rbi.org.in&quot;, .) %&gt;% # prepend the website to the url
  map(read_html) %&gt;% # take previously generated list of urls and read them
  map(html_node, &quot;#raw-url&quot;) %&gt;% # parse out the 'raw' url - the link for the download button
  map(html_attr, &quot;href&quot;) %&gt;% # return the set of raw urls for the download buttons
  str_c(&quot;https://www.rbi.org.in&quot;, .) %&gt;% # prepend the website again to get a full url
  for (url in raw_list)
  { download.file(url, destfile = basename(url), mode = &quot;wb&quot;) 
  } 
  </code></pre>
  <p>I am not able to interpret why is the code erroring out. If someone can help me.</p>