title: VBA to get address from Google result
body: <p>I have found this code which is returning the address of the first result in Google search page.</p>
  <p>I need a similar or new code to get the address of the result which contains a specific website. For example if the third result leads to &quot;www.example.com/address&quot;, I need to get this value back into Excel (&quot;www.example.com/address&quot;).</p>
  <pre><code>Sub XMLHTTP()
  
  Dim url As String, lastRow As Long
  Dim XMLHTTP As Object, html As Object, objResultDiv As Object, objH3 As Object, link As Object
  Dim start_time As Date
  Dim end_time As Date
  
  lastRow = Range(&quot;A&quot; &amp; Rows.Count).End(xlUp).Row
  
  Dim cookie As String
  Dim result_cookie As String
  
  start_time = Time
  Debug.Print &quot;start_time:&quot; &amp; start_time
  
  For i = 2 To lastRow
  
      url = &quot;https://www.google.co.in/search?q=&quot; &amp; Cells(i, 1) &amp; &quot;&amp;rnd=&quot; &amp; WorksheetFunction.RandBetween(1, 10000)
  
      Set XMLHTTP = CreateObject(&quot;MSXML2.serverXMLHTTP&quot;)
      XMLHTTP.Open &quot;GET&quot;, url, False
      XMLHTTP.setRequestHeader &quot;Content-Type&quot;, &quot;text/xml&quot;
      XMLHTTP.setRequestHeader &quot;User-Agent&quot;, &quot;Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0&quot;
      XMLHTTP.send
  
          Set html = CreateObject(&quot;htmlfile&quot;)
      html.body.innerHTML = XMLHTTP.ResponseText
      Set objResultDiv = html.getelementbyid(&quot;rso&quot;)
      Set objH3 = objResultDiv.getelementsbytagname(&quot;H3&quot;)(0)
      Set link = objH3.getelementsbytagname(&quot;a&quot;)(0)
  
  
      str_text = Replace(link.innerHTML, &quot;&lt;EM&gt;&quot;, &quot;&quot;)
      str_text = Replace(str_text, &quot;&lt;/EM&gt;&quot;, &quot;&quot;)
  
      Cells(i, 2) = str_text
      Cells(i, 3) = link.href
      DoEvents
  Next
  
  end_time = Time
  Debug.Print &quot;end_time:&quot; &amp; end_time
  
  Debug.Print &quot;done&quot; &amp; &quot;Time taken : &quot; &amp; DateDiff(&quot;n&quot;, start_time, end_time)
      MsgBox &quot;done&quot; &amp; &quot;Time taken : &quot; &amp; DateDiff(&quot;n&quot;, start_time, end_time)
  End Sub
  </code></pre>