Skip to content Skip to sidebar Skip to footer

Cannot Extract Data From A Span Itemprop

I have the following to extract some prices and availabilities from a webpage. But I get Object Required at: Set price = ie.Document.querySelector('.price-cont .final-price') Why?

Solution 1:

Hard to tell without seeing HTML/URL. Have you verified the selector is correct?

Otherwise, the main two things you can do now, in relation to allowing enough time for page to load, are:

1) Add a proper wait before attempting to select

While ie.Busy Or ie.readyState < 4: DoEvents: Wend

2) Try a timed loop to allow further load time

Option Explicit
Public Sub LoopUntilSet()
    Dim price As Object, t As Date
    Const MAX_WAIT_SEC As Long = 5

    'your other code

    While ie.Busy Or ie.readyState < 4: DoEvents: Wend
    t = Timer
    Do
        DoEvents
        On Error Resume Next
        Set price = ie.document.querySelector(".price-cont .price")
        If Timer - t > MAX_WAIT_SEC Then Exit Do
        On Error GoTo 0
    Loop
    If price Is Nothing Then Exit Sub

    'other code.....
End Sub

3) Remove the [] from around i


Post a Comment for "Cannot Extract Data From A Span Itemprop"