javascript - VBA 检查网页上的警报 <li> </li> 并在检测到时运行 Sub

标签 javascript excel vba internet-explorer web-scraping

我正在尝试比较 li 中的刺痛 这一个可能非常简单,我尝试做与循环浏览网站生成的表格上的 Href 相同的事情,但它没有'一样工作。

<div class="text" id="vs" style="left: 908px; top: 97px; width: 391px; color: red; position: absolute; z-index: 251;">
    <ul><li>Has Duplicated Billed Line Item(s).</li></ul>
</div>

这是我目前所拥有的,但红色变量没有填充

Set allalert = appIE.document.getElementById("vs").getElementsByTagName("li")
For Each alert In allalert
If alert = "Has Duplicated Billed Line Item(s)." Then
 Call Dupe_Bill_process
Next alert

非常感谢任何帮助,感谢在整个学习过程中帮助我的每个人,我实际上已经对这些东西感到满意了哈哈

最佳答案

您需要与 .innerText 属性进行比较,就像您目前正在与一个对象进行比较一样。您还可以删除过时的 call 关键字。

Set allalert = appIE.document.getElementById("vs").getElementsByTagName("li")
For Each alert In allalert
If alert.innerText = "Has Duplicated Billed Line Item(s)." Then
    Dupe_Bill_process
    'Exit For ''?
Next alert

如果您想在第一次匹配后立即退出,您可能需要一个Exit For。或者简单地使用 appIE.document.getElementById("vs").getElementsByTagName("li")(0)


我还会考虑使用 css 选择器简单地收集一个 nodeList。当您使用实际的浏览器时,这应该会更快。

#vs > ul

即:

Dim nodeList As Object, i As Long
Set nodeList = ie.document.querySelectorAll("#vs > ul")
For i = 0 to nodeList.Length-1
    If nodeList.item(i).innerText = "Has Duplicated Billed Line Item(s)." Then
        Dupe_Bill_process
    End If
Next

如果你只关心第一个匹配的代码就变成了:

If ie.document.querySelector("#vs > ul").innerText = "Has Duplicated Billed Line Item(s)." Then
    Dupe_Bill_process
End If

关于javascript - VBA 检查网页上的警报 <li> </li> 并在检测到时运行 Sub,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54243227/

相关文章:

javascript - 引用函数数组中的另一个函数

vba - 在 VBA 中触发完整计算

xml - 如何在 Open XML SDK 2.5 for excel 中设置来源公司(作者)?

VBA 中的 Excel If 语句

VBA 'For' 函数未完成循环

excel - 从日期格式 VBA 中减去整数

Javascript 字符数

javascript - jQuery 1.4.2 在更改文本字段时使用 .delegate

javascript - safari&IE中链接形状坐标浏览器

python - pd.read_excel ("file.xlsx")不会创建 'DataFrame' 而是 'OrderedDict'