Retrieving Specific Data From Website Through Excel
I am trying to do something very similar to the below existing example: reference problem With one small exception, I need to pull only the rating and # of reviews for this listing
Solution 1:
This code will retrieve the two pieces of information you requested and place them on the activesheet
Sub test()
my_url = "http://www.yelp.com/biz/if-boutique-new-york"
Set html_doc = CreateObject("htmlfile")
Set xml_obj = CreateObject("MSXML2.XMLHTTP")
xml_obj.Open "GET", my_url, False
xml_obj.send
html_doc.body.innerhtml = xml_obj.responseText
Set xml_obj = Nothing
Set Results = html_doc.body.getElementsByTagName("i")
For Each itm In Results
If InStr(1, itm.outerhtml, "star-img", vbTextCompare) > 0 Then
numb_stars = itm.getAttribute("title")
Exit For
Else
End If
Next
Set Results = html_doc.body.getElementsByTagName("span")
For Each itm In Results
If InStr(1, itm.outerhtml, "reviewCount", vbTextCompare) > 0 Then
numb_rev = itm.innertext
Exit For
Else
End If
Next
ActiveCell = numb_stars
ActiveCell.Offset(1, 0) = numb_rev
End Sub
Post a Comment for "Retrieving Specific Data From Website Through Excel"