gpt4 book ai didi

html - Excel VBA 抓取在 HTML 文档中找到的 CSS 元素

转载 作者:行者123 更新时间:2023-11-28 15:31:54 24 4
gpt4 key购买 nike

这是我试图从中抓取的 HTML 文档的一部分:

<div id="abc" class="outer">   
::before
<div class="inner"></div>
::after
</div>

我尝试使用

获取此代码段的 innerHTML
Set Elements = Document.getElementsByClassName("outer")
MsgBox Elements(0).innerHTML

消息框中唯一弹出的是(不带引号):

"<div class="inner"></div>"

innerHTML 似乎忽略了::before 和::after CSS 伪元素。有什么方法可以捕获这些或确定它们是否在那里?

我问的原因是,当我尝试自动化的应用程序处于加载状态时,::before 和::after 元素就在那里。一旦脱离加载状态,这些元素就会消失。

谢谢

最佳答案

我想通了。我最终使用了一种不同于尝试查找::before 和::after 的方法。

注意事项:我观察了 HTML 文档如何随着搜索的进行而发生变化,并注意到当应用程序进入或退出加载状态时,我上面包含的 HTML 片段的父级发生了变化。

<div id="snippetParent" class="overlay" style="width: 100%; height: 100%; top: 0px; left: 0px; position: absolute; display: block;">

<div id="abc" class="outer">
<div class="inner"></div>
</div>

</div>

“Style”属性的“display”属性在加载时变为“display: block”,不加载时变为“display: none”。

如果应用程序加载时间过长,还会出现一个弹出窗口(弹出窗口 ID 是“弹出窗口”,用于此问题)。这个弹出窗口使上面提到的样式从 block 变为无。我必须在 while 循环中包含弹出窗口何时出现的条件。

在任何加载指示器消失之前,“good” bool 值都是 false。然后它变为真并因此退出 while 循环。

这是我的代码:

Do While good = False
For Each tx In Split(Document.getElementById("snippetParent").Style.cssText, "; ")
If tx = "display: block" Then
good = False
UpdateBrowser BB:=Browser, waitSeconds:="02"
ElseIf tx = "display: none" Then
txtDocument = ""
On Error Resume Next
txtDocument = Document.getElementById("popup").innerHTML

If txtDocument = "<b>Retrieving Data...</b>" Then
Beep
UpdateBrowser BB:=Browser, waitSeconds:="02"
Else
good = True
End If
Else
'Not display
End If
Next tx
Loop

关于html - Excel VBA 抓取在 HTML 文档中找到的 CSS 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44549262/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com