title: Scrape with a loop and avoid 404 error
body: <p>I am trying to scrape wiki for certain astronomy related definitions for my project. The code works pretty well, but I am not able to avoid 404s. I tried <code>tryCatch</code>. I think I am missing something here.</p>
  
  <p>I am looking for a way overcome 404s while running a loop. Here is my code:</p>
  
  <pre><code>library(rvest)
  library(httr)
  library(XML)
  library(tm)
  
  
  topic&lt;-c("Neutron star", "Black hole", "sagittarius A")
  
  for(i in topic){
  
    site&lt;- paste("https://en.wikipedia.org/wiki/", i)
    site &lt;- read_html(site)
  
    stats&lt;- xmlValue(getNodeSet(htmlParse(site),"//p")[[1]]) #only the first paragraph
    #error = function(e){NA}
  
    stats[["topic"]] &lt;- i
  
    stats&lt;- gsub('\\[.*?\\]', '', stats)
    #stats&lt;-stats[!duplicated(stats),]
    #out.file &lt;- data.frame(rbind(stats,F[i]))
  
    output&lt;-rbind(stats,i)
  
  }
  </code></pre>