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

ebay product data

Sharid

New Member
Hi

I have an ebay code that extracts data about products, but the code only half works. I have two issues

1) It places the data into the FIRST BLANK cell in the column, when it should be for that item
2) The code half runs and then I get an error message which I can not work out.

I'm hoping that someone with a bit more experience can take a look as I can not take it any further as I have been stuck on this for weeks.

I have attached the file, problem is in the code in button1

Sheet2 Shows how the data should be
 

Attachments

  • Ebay Code Example.xlsm
    35.4 KB · Views: 9
Marc L

Firstly Thankyou for replying I have been waiting days for help.

Secondly I am not 100% sure what you mean by your reply. This might NOT sound right but I know that if you inspect elements via IE the class show different to how they do via Chrome or Firefox, also eBay.co.uk will show elements diffrent to .com

As I am using IE and ebay.co.uk it has to be done via how IE sees the Class and elements.

Internet Explorer
66129

FireFox
66130

Chrome same as Firefox
66131

Is this what you mean when you say "calls item or class which do not exist " As you might be using a diffrent browser. Or are you seeing something that I am NOT. Please could you get back as I am still stuck on this one.

Thanks
 
Just see which codelines raise an error : if it calls a class for example, this class does not exist.​
You have to check first the Length (must be > 0) of a web collection to see if​
it contains at least an element like from many samples of this forum in this thread …​
 
Marc L

Thanks for your reply and guidance. I have done as you said and I think this is the problem. Apart from the Urls and Titles, NONE of the other information is in the right order. The code is filling the FIRST BLANK CELL in the column. So as the code loops it runs out of items for a class and the error message pops up.

I have done as you stated and worked through each class, each time i comment a class out, it pulls of more information of the site, BUT the error moves to the next line of code, this way I will have to comment out ALL of the code apart from URLS and Title

66135

The code below has been commented out, EACH TIME I commented the code out it moved the error to the following line, see numbers in YELLOW.
This will continue until I have only URLS and Title left.
66136

This is how the information should go in, items should go into the right cells for each product and NOT in the first BLANK row, if that cell needs to be filled with a string then the word "Nil" can go into it to state nothing was found.
66137
 
  1. Restart your code to write just the first column, remove or put in comment any codeline for other column …

  2. If it crashes, see the samples in this forum how to check the Length of a web collection like the link in my previous post.

  3. Once the code well works for a column, add the necessary codelines for the next column … If it crashes ► step 2.
 
Marc L
Thanks for your support and guidance it is much appreciated.

I have done as you have asked and the code give me the following error, regardless of what line of code I use. i also used an application time wait
Code:
Application.Wait Now + TimeSerial(0, 0, 10)

66139

Only Urls
66140

Any Other Line of code
6614166142

As for the Length of a url it can be upto 32k per cell "Microsoft Excel has a character limit of 32,767 characters" MicroSoft Excel specifications and limits
I checked this before I started as some URl can be very long
 
I was think of changing the code to what is below, so it works as an IF statement so, if nothing is found it place a "Nil" in the cell, that way it can not paste the data into the first blank cell, but I am getting an error message,

66143

Error Line
66144
Also the bits at the bottom that are commeneted out don't work

Code:
  Dim ie As Object
    Dim htmlDoc As Object
    Dim nextPageElement As Object
    Dim div As Object
    Dim link As Object
    Dim URL As String
    Dim pageNumber As Long
    Dim i As Long
    Dim class As String
'    Dim class As Object
'    Dim Workbook As Sheet1
    
    ' Takes Url from Sheet2 A1 seach from Keyword from B1 and places IE
     URL = Sheets("Sheet1").Range("A2").Value & Replace(Worksheets("Sheet1").Range("B2").Value, " ", "+")

    Set ie = CreateObject("InternetExplorer.Application")
    
    With ie
        .Visible = True
        .navigate URL
        Do While .Busy Or .readyState <> 4
            DoEvents
        Loop
    End With

    Application.Wait Now + TimeSerial(0, 0, 5)
    Set htmlDoc = ie.document
    pageNumber = 1
    i = 4
    Do
    
    For Each link In htmlDoc.getElementsByTagName("a")
            If link.getAttribute("class") = "vip" Then
                Cells(i, 1).Value = link.getAttribute("href")
                i = i + 1
            Else
            If link.getAttribute("class")  Is Nothing Then
            Cells(i, 1).Value = "Nil"
            End If

 
            If link.getAttribute("class") Is Nothing Then
                Cells(i, 2).Value = "Nil"
            'End If
                    Else
                If link.getAttribute("class") = "lvtitle" Then
                   Cells(i, 2).Value = link.getAttribute("innertext")
                i = i + 1
                End If
            
    
            If link.getAttribute("class") Is Nothing Then
                Cells(i, 3).Value = "Nil"
            'End If
                Else
                   If link.getAttribute("class") = "hotness-signal red" Then
                     Cells(i, 3).Value = link.getAttribute("innertext")
                 i = i + 1
                End If
            
           If link.getAttribute("class") Is Nothing Then
                Cells(i, 4).Value = "Nil"
               ' End If
                Else
                    If link.getAttribute("prRange") = "lvtitle" Then
                      Cells(i, 4).Value = link.getAttribute("innertext")
                   i = i + 1
            End If
    
'        Next link
'       ' Clicks and goes to next page
'        If pageNumber >= 1 Then Exit Do
'        Set nextPageElement = htmlDoc.getElementsByClassName("gspr next")(0)
'        If nextPageElement Is Nothing Then Exit Do
'
'        nextPageElement.Click 'next web page
'        Do While ie.Busy Or ie.readyState <> 4
'            DoEvents
'        Loop
'        Application.Wait Now + TimeSerial(0, 0, 5)
'        Set htmlDoc = ie.document
'        pageNumber = pageNumber + 1
'    Loop
ie.Quit
    Set ie = Nothing
    Set htmlDoc = Nothing
    Set nextPageElement = Nothing
    Set div = Nothing
    Set link = Nothing

 MsgBox "All Done"
 End If
  End If
   End If
    End If
    Next
    Loop
 
Application.Wait is useless here after Navigate if only you just apply the way in the link …​
As for the Length of a url
You misread & misunderstood : that's nothing to do with any string length​
but the length of a web collection (aka elements #) so just see again the link​
as it's the only way for a clean code to check if an element exists (so you can trash your last code)…​
Or you may use the dirty way : add an On Error Resume Next codeline before looping the webpage items.​
Check only with the IE inspector tool each element needed to fill a sheet column​
as I see at least one which does not exist anywhere in the webpage code ‼​
And some classes are missing in some webpage items …​
 
Thanks for the update,
I see at least one which does not exist anywhere in the webpage code
can you at least say which one does not exist, as I took them off the page and I can then double check.

As for now I CAN NOT take this any futher as this is out of my depth. I have been struggling on this for ages. I ahev tried to debug it but everything I try does not worl and I am limited in VBA.
 
Back
Top