• 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 amend my script to place the parsed items in it's respective rows next to concerning links?

shahin

Active Member
I've written some code in vba to get ASIN from amazon website. My scraper is capable of fetching it flawlessly. However, when I try to place that parsed ASIN in respective rows next to it's base link, it fails. It always gets placed in first empty rows whereas I expected those numbers to be printed in those specific rows in which the left sided adjacent rows are filled in with correct links. I've given two examples below to bring the clarity about what I wanna achieve.

Script I'm trying with:
Code:
Sub Find_Asin()
    Dim HTTP As New XMLHTTP60, html As New HTMLDocument
    Dim post As Object, elem As Range

    For Each elem In Sheet1.Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)

        With HTTP
            .Open "GET", elem, False
            .send
            html.body.innerHTML = .responseText
        End With
      
        For Each post In html.getElementsByTagName("a")
            If InStr(post.href, "dp_cerb_1") > 0 Then
                r = r + 1: Cells(r, 2) = Split(Split(post.href, "dp/")(1), "/")(0)
            Exit For
            End If
        Next post
  
    Next elem
End Sub

The links I've tried with available in the first column starting from Range("A1") in "Sheet1"
Code:
https://www.yify-torrent.org/search/1080p/
https://www.amazon.com/dp/B01LTIORC8
https://www.houzz.com/professionals/
https://chandoo.org/forum/forums/vba-macros/
https://www.amazon.com/dp/B01LTIORC8
https://stackoverflow.com/questions

I expect my scraper to place the collected ASIN next to the cell containing `amazon` link.

I'm getting like this:
Code:
Link                         ASIN
1. Some other link    Number
2. Some other link    Number
3. Amazon link
4. Some other link
5. Amazon link
5. Some other link


I'm expecting like this:
Code:
Link                         ASIN
1. Some other link  
2. Some other link  
3. Amazon link         Number
4. Some other link
5. Amazon link         Number
5. Some other link
 
Last edited:
Just as I thought!! It's a magical solution. Thanks a lot sir chihiro. Btw, I found it working by putting "r = r + 1" outside "ForEach post" loop.
 
Back
Top