Grab Search Results Macro

gswizzle

New Member
Joined
Jun 11, 2015
Messages
9
Hello all! I'm trying to grab the search result URLS from this search (motorcycle -sign -vest -camper -scooter -jacket -goggles -kids -helmet -gloves -attorney -repairs -parts -stock -trailer on SearchTempest), and paste them into the A column of my worksheet.

This is what I have so far
Code:
Sub UrlGrab()



Dim URL As String
Dim HTMLdoc As Object
Dim Anchor As Object
Dim Anchors As Object




URL = "http://www.searchtempest.com/search?search_string=motorcycle+-sign+-vest+-camper+-scooter+-jacket+-goggles+-kids+-helmet+-gloves+-attorney+-repairs+-parts+-stock+-trailer&category=8&Region=na&cityselect=zip&location=37923&maxDist=1500&region_us=1&srchType=&hasPic=&keytype=adv&minAsk=&maxAsk=&subcat=sss"
    


     Set XMLHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
     XMLHTTP.Open "GET", URL, False
     XMLHTTP.send
           
     text = XMLHTTP.responseText
     Set HTMLdoc = CreateObject("htmlfile")
            HTMLdoc.Write text
            HTMLdoc.Close
    


  Set Anchors = HTMLdoc.getElementsByTagName("gs-result")
              
            For Each Anchor In Anchors
                If Anchor.className = "gs-title" Then
                    Rng.Offset(row, 0).Value = Anchor.href
                    row = row + 1
                End If
            Next Anchor
  


    MsgBox "Done!"
End Sub

But nothing happens when I execute this, and only the Message Box appears. Any help is appreciated!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
John,
This is what I've updated my code to:
Code:
Sub UrlGrab()





Dim URL As String
Dim HTMLdoc As Object
Dim Anchor As Object
Dim Anchors As Object
Dim XMLHTTP As Object
Dim Text As String
Dim Row As Long
Dim Rng As Range


    


URL = "http://www.searchtempest.com/search?search_string=motorcycle+-sign+-vest+-camper+-scooter+-jacket+-goggles+-kids+-helmet+-gloves+-attorney+-repairs+-parts+-stock+-trailer&category=8&Region=na&cityselect=zip&location=37923&maxDist=1500&region_us=1&srchType=&hasPic=&keytype=adv&minAsk=&maxAsk=&subcat=sss"
    




     Set XMLHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
     XMLHTTP.Open "GET", URL, False
     XMLHTTP.send
           
     Text = XMLHTTP.responseText
     Set HTMLdoc = CreateObject("htmlfile")
            HTMLdoc.Write Text
            HTMLdoc.Close
    




  Set Anchors = HTMLdoc.getElementsByTagName("A")
              
            For Each Anchor In Anchors
                If Anchor.className = "gs-title" Then
                    Rng.Offset(Row, 0).Value = Anchor.href
                    Row = Row + 1
                End If
            Next Anchor
  




    MsgBox "Done!"
End Sub

And still nothing appears. Am I still calling getElementsByTagName incorrectly?

Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,503
Messages
6,125,175
Members
449,212
Latest member
kenmaldonado

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top