GetelementsByTagName似乎无法正常工作 [英] GetelementsByTagName seems to not work properly

查看:169
本文介绍了GetelementsByTagName似乎无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题听起来很愚蠢,但是当我使用GetElementsByTagname(frame)函数时,它只返回3作为长度而不是我预期的5?

this question sounds stupid but how come when I use the function GetElementsByTagname("frame") , it only returns 3 as a length and not 5 as I expected ?

以下是网页的HTML ,其中我计算了该标记名的5倍框架,但当我在VBA中询问长度时,我得到3 ...

Here is the HTML of the webpage where I counted 5 times the apparition of the tagname "frame" but when I ask for the length in VBA I get 3...

我的观察结果:

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

1) You can see that 3 is the number of main frames (top_navigation, contentframe, dummyframe)

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

2) If I try to access to one of the mainframes via getelementbyname, it works but if I try to access on the the subframes of contentframe ( leftnavigation or postfachcontent) it doesn't work ( 0 item detected)

这是我的代码:

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...


推荐答案

该页面上只有3个框架,其余部分位于嵌入式html框架内,getElementsByTagName无法访问,因为它是一个不同的DOM树。

Only 3 frames are on that page, the rest are inside an embedded html frame which getElementsByTagName cannot access as it is a different DOM tree.

这篇关于GetelementsByTagName似乎无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆