+ Reply to Thread
Results 1 to 3 of 3

Help Grabbing Search Urls

Hybrid View

  1. #1
    Registered User
    Join Date
    07-22-2015
    Location
    Knoxville
    MS-Off Ver
    2007
    Posts
    5

    Help Grabbing Search Urls

    Hello all! I'm trying to grab the search result URLS from this search (http://www.searchtempest.com/search?...sk=&subcat=sss), and paste them into the A column of my worksheet.

    This is what I have so far
     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 and Im not sure what i'm doing incorrectly. Any help is appreciated!

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Help Grabbing Search Urls

    Not sure what is causing this, but when I run your code, IE opens with a "Navigation Cancelled" error. I also had to add a few declarations to get it to run.
    Here is the code I used after adding the declarations..
    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("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
    Last edited by gmr4evr1; 01-03-2016 at 07:17 PM.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    07-22-2015
    Location
    Knoxville
    MS-Off Ver
    2007
    Posts
    5

    Re: Help Grabbing Search Urls

    gmr4evr1,

    Thanks for that correction. i think that I'm using getElementsByTagName incorrectly? I utilized this change:

    Set Anchors = HTMLdoc.getElementsByTagName("A")
    but still nothing is appearing.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Grabbing one value for a cell
    By kbiro in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-20-2015, 12:55 PM
  2. Grabbing Image Url
    By deadmanramsey in forum Excel General
    Replies: 6
    Last Post: 03-25-2014, 10:20 AM
  3. Converting text URLs to hyperlinked URLs
    By ranchhand in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2011, 01:46 PM
  4. Grabbing a name
    By Sheepkin_Coat in forum Excel General
    Replies: 2
    Last Post: 09-23-2010, 02:49 AM
  5. Grabbing Data VBA
    By lienlee in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-23-2010, 01:48 PM
  6. Grabbing info from 1 col to another ?
    By davidstokes in forum Excel General
    Replies: 5
    Last Post: 09-27-2009, 10:14 AM
  7. Grabbing the Last name
    By MABeatty in forum Excel General
    Replies: 6
    Last Post: 06-23-2006, 02:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1