1

下面的 HTML 代码充当工具提示信息,出现在鼠标悬停在链接上。使用 .getelementbyclassname 方法,我无法从页面中获取值“故事和体验”。我猜,在加载时工具提示可见之前,HTML 代码不可用于提取。如何使其可见或提取数据?

我正在使用 EXCEL VBA 来执行此操作。

 <div id="ext-comp-1115" class="x-tip rich-tooltip" style="position: absolute; z-index: 25000; visibility: hidden; padding: 3px 0px 5px; width: 323px; left: 131px; top: 168px; display: none;">
<div class="ellipsis">Type: <span class="rich-tooltip-item">Story &amp; Experience</span></div></div></div>

VBA代码:

Dim IE As New InternetExplorer
IE.navigate "https://swym.3ds.com/#post:16884"
IE.Visible = True
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Application.Wait (Now() + TimeValue("00:00:016"))
Dim doc As HTMLDocument
Set doc = IE.document
Dim dd As Variant
dd = doc.getElementsByClassName("ellipsis").tags("span") 
MsgBox dd 

谢谢

4

1 回答 1

0

doc.getElementsByClassName("ellipsis").tags("span") 返回一个对象而不是字符串值。我相信您正在寻找标签的 innerText 属性,所以要么......

'Set dd equal to the "span" tag object
Set dd = doc.getElementsByClassName("ellipsis").tags("span")
MsgBox dd.innerText

或者

'Assign the "span" tag object's innerText string value to the dd variable
dd = doc.getElementsByClassName("ellipsis").tags("span").innerText
MsgBox dd
于 2021-03-17T19:16:50.727 回答