Hi, I have a list of webpage links on the sheet "memory" in column H and using the macro attached I am getting the price tag from elements ... list_item_price, but if the macro does not find the list_item_price it returns the previous price instead, I would like it to display "it does not exist". The other thing is I would like to first check if the element exist on the webpage at all, and if not look for element with different name, since there are several differently programmed eshops, thus using different names for the price tag. Thank You for your help.
Code:
Sub Scrape1()
Dim ObjIE As Object
Dim record As Range
Dim ws As Worksheet
Set ws = ActiveWorkbook.Worksheets("Memory")
For Each record In Range(ws.Cells(3, 8), ws.Cells(ws.Cells.SpecialCells(xlCellTypeLastCell).Row, 8))
Set ObjIE = CreateObject("InternetExplorer.Application")
ObjIE.Navigate record.Value
Application.StatusBar = "Loading, Please wait..."
Do While ObjIE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Application.StatusBar = "Searching for value. Please wait..."
Dim dd As String
On Error Resume Next
dd = ObjIE.Document.getElementsByClassName("col-md-6 col-sm-6 col-6 list_item_price")(0).innertext
'If ObjIE.Document.getElementsByClassName.Count > 0 Then
If InStr(1, ObjIE.Document.getElementsByClassName.innertext, "col-md-6 col-sm-6 col-6 list_item_price") > 0 Then
record.Offset(0, 1).Value = dd
' Element exists and is not empty
Else
record.Offset(0, 1).Value = "Does not exist"
End If
Next record
ObjIE.Quit
End Sub