• 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.

Data are getting fetched along with bunch of duplicates

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
 
Thanks Marc L, for your priceless comment. You saved my day. I was tearing my hair thinking that I was doing something wrong. However, I got relieved from it seeing your judicious opinion. Thanks again.
 
Back
Top