title: How to check if a string is the title of a Wikipedia article with R?
body: <p>Suppose I have a list of strings :</p>
  
  <p><code>strings &lt;- c("dog", "cat", "animal", "bird", "birds", "bqpohd", "ohphha", "mqphihpha", "aphhphohpa", "pohha")</code></p>
  
  <p>I would like to check if these strings are the titles of Wikipedia articles.</p>
  
  <p>Here is a solution but I presume that it is not the quickest way to do this task for long lists:</p>
  
  <pre><code>results.df &lt;- CheckIfAStringIsTheTitleOfAWikipediaArticle(strings)
  View(results.df)
  CheckIfAStringIsTheTitleOfAWikipediaArticle &lt;- function(strings){
    start_time &lt;- Sys.time()
      Check &lt;- function(string){
      GetPageID &lt;- function(string){
    query &lt;- paste0("https://en.wikipedia.org/w/api.php?", 
                    "action=query", "&amp;format=xml", "&amp;titles=", string)
    answer &lt;- httr::GET(query)
    library(xml2)
    library(httr)
    page.xml &lt;- xml2::read_xml(answer)
    nodes &lt;- xml_find_all(page.xml, ".//query//pages//page")
    pageid &lt;- xml_attr(nodes, "pageid", ns = character(), 
                       default = NA_character_)
    return(pageid)
    }
  
    IsValidPageName &lt;- function(string){
      pageid&lt;- GetPageID(string)
      if(!is.na(pageid)){return(TRUE)}
      else{return(FALSE)}
    }
  
    boolean &lt;- IsValidPageName(string)
    return(boolean)
    }
  
    validTitle &lt;- unlist(lapply(strings, Check))
    results.df &lt;- data.frame(strings, validTitle)
    end_time &lt;- Sys.time()
    time &lt;- end_time - start_time
    print(time)
    return(results.df)
  }
  
  </code></pre>
  
  <p>Thank you very much for your help !</p>