1

这个问题听起来很愚蠢,但是当我使用函数GetElementsByTagname(“frame”)时,它只返回3作为长度而不是5,正如我预期的那样?GetelementsByTagName似乎无法正常工作

这里就是我算的标记名“框架”,但5倍的幽灵,当我问在VBA长度我得到3 ...

我观察了HTML of the webpage

1)你可以看到3是主框架的数量(top_navigation,contentframe,dummyframe)

2)如果我尝试通过getelementbyname访问其中一台主机,它可以工作,但是如果我尝试访问contentframe的子帧(leftnavigation或postfachcontent)它不起作用(0项检测到)

这里是我的代码:

Dim Frame As IHTMLElementCollection 
    Set Frame = IEDoc.getElementsByName("contentframe") ' this works and returns 1 item 
    MsgBox Frame.Length 
    Set Frame = IEDoc.getElementsByName("postfachcontent") 
    MsgBox Frame.Length ' this returns 0 item 


Dim Collection As IHTMLElementCollection 

Set Collection = IEDoc.getElementsByTagName("frame") 
MsgBox Collection.Length ' this returns 3 and I expected 5... 
+0

您是否尝试过使用MSHTML.FramesCollection?从IEDoc.Frames设置? –

+0

我从来没有听说过类型MSHTML.FramesCollection。我如何使用它?如果我简单地将_Collection_的类型更改为它,我当然会遇到不匹配的情况。 – Seb

+0

使用IEDoc.Frames? –

回答

0

只有3张是在该网页上,其余的都是其的getElementsByTagName不能访问,因为它是一个不同的DOM树嵌入HTML框架内。

+0

嗯,我看到了,是有一种方法可以访问这3个主机的内容? – Seb

相关问题