小编Sam*_*Sam的帖子

使用 VBA 检查页面上是否存在元素

我有 15,000 种产品,我需要知道它们是 X、Y 还是 Z。下面的代码在亚马逊上检查产品是否属于 XYZ 类型。

上帝帮助我,它确实有效。唯一的例外是当它搜索亚马逊不再销售的产品时。然后我正在寻找的包含我正在搜索的产品描述的元素 ID 在页面上不存在,并且代码在线中断

text = document.getelementbyID("result_0").innertext
Run Code Online (Sandbox Code Playgroud)

出现错误“对象变量或块变量未设置”。

在继续执行其余代码之前,如何检查元素是否存在?

谢谢!

山姆

Sub LetsAutomateIE()

Dim barcode As String
Dim rowe As Integer
Dim document As HTMLDocument
Set ie = CreateObject("InternetExplorer.Application")
Dim Element As HTMLDivElement
Dim text As String
Dim pos As Integer

rowe = 2

While Not IsEmpty(Cells(rowe, 2))

barcode = Cells(rowe, "B").Value

With ie
.Visible = False
.navigate2 "https://www.amazon.co.uk/s/ref=nb_sb_noss_1?url=search-    
alias%3Daps&field-keywords=" & barcode
Do Until ie.readyState = 4
Loop
End With

Set document = …
Run Code Online (Sandbox Code Playgroud)

excel internet-explorer vba getelementbyid

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

excel ×1

getelementbyid ×1

internet-explorer ×1

vba ×1