Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi, I have this website, where I want the details of the product to be extracted in my excel sheet. I coded by my own... But I am getting an error in the line:

VB
If objdiv4.className = "Section" Then


So here's the full code:

What I have tried:

VB
Sub onmyown()

Dim ie As InternetExplorer
Dim doc As HTMLDocument
Dim sBrand As String, sBrand1 As Integer, sBrand2 As Integer, sBrand3 As Integer, iStart As Integer, iStop As Integer
Dim tr As HTMLTableRow
Dim td As HTMLTableCell


Set ie = New InternetExplorer
 
ie.Visible = False
ie.navigate "https://www.ebay.in/itm/Bushnell-Binocular-With-Ultra-High-Power-8-x-21mm-100m-1000m-with-Carrying-Case-/292199511233?_trksid=p2059707.m48543.l9013"


Do While ie.readyState <> READYSTATE_COMPLETE
Application.StatusBar = "How you Doin ..."
DoEvents
Loop




Set doc = ie.Document


With ThisWorkbook.Worksheets("Sheet1")
    Range("A1:N1").Merge
    Range("A1:N1").HorizontalAlignment = xlCenter
    Range("A1:N1").Cells.Interior.Color = RGB(135, 135, 135)
    Range("A1:N1").Cells.Font.Bold = True
    Range("A1:N1").Cells.Font.Size = 14
    Range("A2:C2") = Array("Price", "Brand", "Specifications")
    Range("A2:C2").Cells.Font.Size = 12
    Range("A2:C2").Cells.Font.Bold = True
End With
    
For Each objDiv In doc.getElementsByTagName("div")
    If objDiv.ID = "CenterPanelInternal" Then
        For Each objh1 In objDiv.getElementsByTagName("h1")
            If objh1.className = "it-ttl" Then
                ThisWorkbook.Worksheets("Sheet1").Range("A1:N1").Value = objh1.outerText
            End If
        Next
        
        For Each objdiv2 In objDiv.getElementsByTagName("div")
            If objdiv2.className = "u-flL w29 vi-price" Then
                ThisWorkbook.Worksheets("Sheet1").Cells(3, 1).Value = objdiv2.outerText
            End If
        Next
    End If

If objDiv.ID = "viTabs" Then
        For Each objdiv3 In objDiv.getElementsByTagName("div")
                If objdiv3.className = "itemAttr" Then
                    For Each objdiv4 In objDiv.getElementsByTagName("div")
                        If objdiv4.className = "section" Then
                            For Each td In objdiv4.getElementsByTagName("tr")
                                If td.className = "attrLabels" Then
                                    If td.outerText = "Brand:" Then
                                        For Each tdvalue In td.getElementsByTagName("span")
                                            ThisWorkbook.Worksheets("Sheet1").Cells(3, 2).Value = tdvalue.outerText
                                        Next
                                    End If
                                End If
                            Next
                        End If
                    Next
                End If
        Next
    End If
Next


End Sub
Posted
Updated 29-Jan-18 7:02am
v3
Comments
[no name] 29-Jan-18 9:44am    
Please post what is the exact error you are getting?
JayyMehta 29-Jan-18 9:57am    
Getting an error of "Object required" in the mentioned line above. I tried creating object too, but then when running it, no change occurs, no output.
Richard MacCutchan 29-Jan-18 12:34pm    
"I saw your answers before "
Ask the person who gave you an answer.
JayyMehta 29-Jan-18 13:11pm    
Wrongly typed...
Richard Deeming 30-Jan-18 11:29am    
For Each objdiv4 In objDiv.getElementsByTagName("div")

Shouldn't that be:
objdiv3.getElementsByTagName("div")

Otherwise, you're just repeating the parent loop.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900