I am attempting to pull google results for a query like this "site:thetrashplate.com". I want the title, description and url to be provided in column a,b,c. Each result would then go into the next row i.e. title2, description2 and url2 would go into a2,b2,c2. Im trying to make the code provide me 100% of all results found for that query.
I realize googles TOS on this and any suggestions on how to utilize google's api would be appreciated but is secondary concern to getting this operational.
The code I have so far is below:
Sub crawlgoogle2()
Dim URL As String, lastRow As Long
Dim xmlHttp As Object, html As Object, objResultDiv As Object, objH3 As Object, link As Object
lastRow = Range("A" & Rows.Count).End(xlUp).Row
URL = "https://www.google.com/search?q=site:autoinsurance-guidance.com"
Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "GET", URL, False
xmlHttp.setRequestHeader "Content-Type", "text/xml"
xmlHttp.send
Set html = CreateObject("htmlfile")
html.body.innerHTML = xmlHttp.ResponseText
Set objResultDiv = html.getelementbyid("rso")
Set objH3 = objResultDiv.getelementsbytagname("H3")(0)
Set link = objH3.getelementsbytagname("a")(0)
str_text = Replace(link.innerHTML, "<EM>", "")
str_text = Replace(str_text, "</EM>", "")
Cells(1, 2) = str_text
Cells(1, 3) = link.href
End Sub
Bookmarks