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

Web scrape for active list and sold list

YasserKhalil

Well-Known Member
Hello everyone
I have this code that scrapes ebay prices and lists
Code:
Sub WebScrapeEBay()
    Dim doc    As HTMLDocument
    Dim ie      As Object
    Dim i      As Integer
    Dim i2      As Integer
   

    Set ie = CreateObject("InternetExplorer.Application")
   
    With ie
        .Visible = False
        For i2 = 0 To 0
            .navigate "http://www.ebay.com/sch/i.html?_from=R40&_trksid=p2055845.m570.l1313.TR0.TRC0.H0.X" & Range("B4").Offset(0, (i2 * 2)).Value & ".TRS0&_nkw=" & Range("B4").Offset(0, (i2 * 2)).Value & "&_sacat=0"
            Do
                DoEvents
            Loop Until ie.readyState = READYSTATE_COMPLETE

            Set doc = ie.document
            While ie.readyState <> 4
            Wend

            On Error Resume Next
            For i = 0 To 500
                Range("B7").Offset(i, (i2 * 2)).Value = doc.getElementById("ResultSetItems").getElementsByTagName("h3")(i).innerText
                Range("B7").Offset(i, (i2 * 2) + 1).Value = doc.getElementById("ResultSetItems").getElementsByClassName("lvprice prc")(i).innerText
            Next i
        Next i2
        ie.Quit
        Application.EnableEvents = True
    End With
   
    MsgBox "Done...", 64
End Sub

I would like to see 2 lists:
First list: Active Listings of items that are "US only", "New", "Buy it Now".
Second list: Sold items that are "US only", "New", "Buy it Now".
 

Attachments

  • Sample.xlsm
    19.9 KB · Views: 8
The expected results vary according to the search item. The code is in the url as I think the url is different when selecting different criteria such as "US only","New" and so on
The expected is to scrape List and Price according to the url provided
 
Yes I know .. But I need to differentiate between active and sold items and in this case how can I deal with the url as it is different?
 
Yes Mr. Marc
I copied the two urls that related to both active and sold .. and made another part (the same as looping in the code attached) then it worked for me
Thanks a lot for help
 

Do not forget again to release ie object variable
or better do not use an object variable
as you can directly point out IE in With codeline …
 
Back
Top