I've created a script to parse recipe
name and serving
from such links. When I run the same script in two different computers, I get expected results in one computer but I encounter this error Run-time error 438 (Object doesn't support this property or method) in another computer. The script throws that error pointing at this line Servings = .Item(I).NextSibling.innerText
within the script below.
The excel version, OS and bit Excel 2019, windows 10, 64bit
of that pc which errors out
.
The excel version, OS and bit Excel 2013, windows 7, 32bit
of that pc which finds success
.
This is the script that I used :
Public Sub FetchRecipeInfo()
Dim Http As Object, Html As HTMLDocument, Servings$, R&
Dim Url As Variant, linkList As Variant, I&, Ws As Worksheet
Set Html = New HTMLDocument
Set Http = CreateObject("MSXML2.XMLHTTP")
Set Ws = ThisWorkbook.Worksheets("Sheet1")
R = 1
linkList = Array( _
"https://www.allrecipes.com/recipe/18871/easy-tuna-casserole/", _
"https://www.allrecipes.com/recipe/21791/tuna-noodle-casserole-iv/" _
)
For Each Url In linkList
With Http
.Open "GET", Url, False
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
.send
Html.body.innerHTML = .responseText
End With
Ws.Cells(R, 1) = Html.querySelector("h1.headline").innerText
With Html.querySelectorAll(".recipe-meta-item-header")
For I = 0 To .Length - 1
If InStr(.item(I).innerText, "Servings:") > 0 Then
Servings = .item(I).NextSibling.innerText
Ws.Cells(R, 2) = Servings
Exit For
End If
Next I
End With
R = R + 1
Next Url
End Sub
Expected output:
Easy Tuna Casserole 8
Why I get results in one pc but encounter
Run-time error 438
in another pc even when I use the same script?