Im looking to create a VBA script which checks a website and pulls the price from the class. My issue there are 2 potential classes ".kuSalePrice kuSpecialPrice" and ".kuSalePrice". I created the below to check if the class ".kuSalePrice" exists and if not, the second class and output the price.
I am getting the following error on the line below
Worksheets("Sheet1").Range("C" & lRow).Value = result2.innerText
"Object variable or with block variable not set"
Sub PriceCheck()
Dim ie As InternetExplorer
Dim doc As HTMLDocument
Dim result As IHTMLElement
Dim result2 As IHTMLElement
Dim url As String
Dim lRow As Long
Set ie = New InternetExplorer
ie.Visible = True
lRow = 2
url = Worksheets("Sheet1").Range("B" & lRow).Value
Do Until url = ""
ie.navigate url
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Set doc = ie.document
Set result = doc.querySelector(".SalePrice")
If IsObject(doc.querySelector(".SalePrice")) Then
MsgBox "does exsist"
Set result2 = result
Else
MsgBox "doesnt exsist"
Set result2 = doc.querySelector(".SalePrice SpecialPrice")
End If
Worksheets("Sheet1").Range("C" & lRow).Value = result2.innerText
lRow = lRow + 1
url = Worksheets("Sheet1").Range("B" & lRow).Value
Loop
Cells.Replace What:="£", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
End Sub