title: readLines() webscraping cannot open connection in r
body: <p>I am using Windows 7 with R3.3.1. I have a data frame called <code>idsFinal_Attack</code> that has two columns. </p>
  
  <pre><code>Attack Type   
  1                                                    40674 
  2 Netcore.Netis.Devices.Hardcoded.Password.Security.Bypass 
  3                                  DNS.Invalid.Size.Attack  
  4                       Acunetix.Web.Vulnerability.Scanner  
  5                                   SIPVicious.SIP.Scanner  
  6                                                    17799   
  New
  1                                   SIPVicious.SIP.Scanner
  2 Netcore.Netis.Devices.Hardcoded.Password.Security.Bypass
  3                                  DNS.Invalid.Size.Attack
  4                       Acunetix.Web.Vulnerability.Scanner
  5                                   SIPVicious.SIP.Scanner
  6                               MS.SMBv2.Infinite.Loop.DoS  
  </code></pre>
  
  <p>The first is "Attack Type" consisting of both character and numeric ID's. The second column is what I wish to fill in with the code below. </p>
  
  <pre><code>URL = 'http://www.fortinet.com/ids/VID'
  idsFinal_Attack$New = character(length = nrow(idsFinal_Attack))
  
  for (i in 1:nrow(idsFinal_Attack)) {
      if (is.na(as.numeric(idsFinal_Attack$`Attack Type`[i]))) {
              idsFinal_Attack$New[i] = idsFinal_Attack$`Attack Type`[i]
      } else {
              fortinetPage = readLines(paste0(URL, idsFinal_Attack$`Attack Type`[i]))
              fortinetPage = grep("id=\"ency_title\"&gt;Vulnerability:", fortinetPage, 
                                  value = TRUE)
              idsFinal_Attack$New[i] = 
                      gsub("&lt;h1 id=\"ency_title\"&gt;Vulnerability: |&lt;/h1&gt;", "", fortinetPage)
      }
  }
  </code></pre>
  
  <p>For rows in "Attack Type" that contain a character string, I wish to copy and paste that string into the adjacent cell of column "New". For rows in "Attack Type" that contain numeric entries, like row 1, I wish to paste that numeric value to the end of variable "URL", then use the <code>readLines()</code> function to extract a portion of the webpage that the augmented "URL" variable takes me to, i.e. <a href="http://www.fortinet.com/ids/VID40674" rel="nofollow">http://www.fortinet.com/ids/VID40674</a>. I only need a small section of the webpage titled "Vulnerability" with the subsequent text. <code>readLines()</code> returns all the text from the webpage, and then I can use grep and gsub to get the desired section. The data frame <code>idsFinal_Attack</code> has 145 rows, 67 of which are numeric and will require a readLines() command. The code below works for about half of them, and then throws the error shown below. </p>
  
  <blockquote>
  <pre><code>Error in readLines(url(paste0(URL, idsFinal_Attack$`Attack Type`[i]), 
  :  cannot open the connection
  </code></pre>
  </blockquote>
  
  <p>This is my first attempt, and I realize the code can be made more concise. I just wanted to get a working version. I have briefly experimented with the XML and rvest packages, but have not had any lucky. Does anybody have any suggestions?</p>