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:
The links I've tried with available in the first column starting from Range("A1") in "Sheet1"
I expect my scraper to place the collected ASIN next to the cell containing `amazon` link.
I'm getting like this:
I'm expecting like this:
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: