• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to scrape all links from a page?

Christo Juan

New Member
Hello,
I am SO lost. I have an awesome script that, for each row with a search term in column A, it adds the URL from the #1 position on the google search page to column B.

What I want is for it to scrape all of the (organic) links - those that have the same element as the one mentioned - and place them in columns C-K so that the url for Google position #1 is in column C, #2 is in D, #3 is in E etc.

I am just learning VBA and have tried playing around with solutions listed below but I can quite seem to figure out how to add the simple loop that would get this done :(

*'https://stackoverflow.com/questions...h-in-ie-and-return-the-hyperlink-of-the-first
*'https://www.ozgrid.com/forum/forum/...t-the-href-value-out-from-the-given-html-code
*'https://chandoo.org/forum/threads/list-urls-that-include-specific-string.36075/ good but vertical

Help would be very much appreciated...
Thanks!
Chris


▬▬▬▬▬▬▬▬▬ Mod edit : thread moved to appropriate forum !
 

Attachments

  • google_results-organic-simple.xlsm
    391 KB · Views: 12
Hi Christo Juan,

To turn the vertical to horizontal, I think you need to alter only this piece of code that iterates over the rows in column A.
Code:
For Each objLink In objLinks
        Cells(i, "A").Value = objLink.href
        i = i + 1
    Next

In you solution it would be more like (I'm not sure where the DoEvents must come):
Code:
For i = 2 To lastRow
//your  code
         For j = 2 To 11
            Cells(i, j) = link.href
            DoEvents
            j = j + 1
        Next
Next
//your code
where i is your row iterator you already have in your code. And j is the new one, where you iterate the columns.
I think that might work. Given you put the 2nd counter in the correct place in your VBA, which I already find rather impressive for a newby like you say.
I'm not such a VBA expert as many others are in this forum. Let's hope they can come up with something robust.

Cheers,
Guido
 
Guido,
Thanks very much for that feedback. I appreciate it.
Hopefully, others will reply with some guidance on looping through all 10 google results.
Chris
 
Back
Top