shahin
Active Member
Hi there! Got a seriously convoluted situation n can't settle the issue myself. While scraping I could notice that my code is running smoothly. The only problem is it produces lots of duplicates. I also tried with three different "htmldocument" variables but the results are always the same. Hope someone will help me point out what I'm doing wrong in my code. Thanks a lot in advance.
Code:
Sub OlxData()
Dim http As New MSXML2.ServerXMLHTTP60
Dim html As New HTMLDocument
Dim str As String, strr As String
With http
.Open "GET", "https://www.olx.com.pk/", False
.send
html.body.innerHTML = .responseText
End With
Set docs = html.getElementsByClassName("cat-main tdnone")
For Each doc In docs
str = doc.href
With http
.Open "GET", str, False
.send
html.body.innerHTML = .responseText
End With
Set elems = html.getElementsByClassName("link-relatedcategory lheight16 icongridbox lheight16 cat-1411 tdnone block icon-link")
For Each elem In elems
strr = elem.href
With http
.Open "GET", strr, False
.send
html.body.innerHTML = .responseText
End With
Set items = html.getElementsByClassName("large lheight20 margintop10")
For Each item In items
x = x + 1
Cells(x, 1) = item.getElementsByTagName("span")(0).innerText
Next item
Next elem
Next doc
Set docs = Nothing: Set items = Nothing: Set elems = Nothing
End Sub