Dom 为什么这个vbscript不获取任何值?
我试图编写一个vbscript,从Dom 为什么这个vbscript不获取任何值?,dom,vbscript,Dom,Vbscript,我试图编写一个vbscript,从 它不显示任何值,但您可以查看页面的源代码,您可以看到它有一个带有类的
它不显示任何值,但您可以查看页面的源代码,您可以看到它有一个带有类的
我不明白为什么它没有显示在我的脚本中
'Initializing object with Internet Explorer Application
set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
'setting properties of Internet Explorer to the newly create object
with IE
.Visible = 0
.navigate "http://www.roku.com/channels/#!details/12" 'INSERT WEBPAGE HERE
end with
'waiting for IE to load the page
'tried using IE.busy or IE.readyState <> 4 also
while IE.busy
wScript.sleep 500
wend
wScript.sleep 500
'getting all image tags from the webpage
Set imgTags = IE.document.getElementsByTagName("IMG")
'iterating through the image tags to find the one with the class name specified
For Each imgTag In imgTags
'tried imgTag.className also
If imgTag.getAttribute("class") = "cs-poster-big" Then MsgBox "src is " & imgTag.src
next
IE.quit
set IE= Nothing
MsgBox "End of script"
以避免动态生成内容的问题
此外,在IE8中,需要更改代码以获取映像的类名。应该是
http://www.roku.com/channels?_escaped_fragment_=details/12/netflix#!details/12/netflix
在IE.Busy或IE.ReadyState 4时执行
WScript.Sleep 100
环
设置imgTags=IE.document.getElementsByTagName(“IMG”)
对于imgTags中的每个imgTag
imgClass=imgtag.getAttribute(“类”)
如果为空(imgClass),则
imgClass=imgTag.className
如果结束
如果imgclass=“cs海报大”,则
MsgBox“src is”&imgTag.src
如果结束
下一个
但这不是一个解决方案,只是一个变通办法。+1因为它在大约3次中都运行良好。但是现在它在Set imgTags=IE.document.getElementsByTagName(“IMG”)
行中给了我一个未指定的错误80004005
。有什么建议吗?错误80004005通常指的是某种权利问题。在我看来,IE加载完成后,您的代码会尝试访问页面内容,但一些超时回调已开始执行,无法访问内容。使用错误控制包装对文档属性/方法的所有访问,并在出现错误时等待。您可以查看文档。readyState=“complete”将试用并让您知道……)结果很好,伙计。。。谢谢……)但是我可以知道为什么问题中给出的URL不起作用,而您给出的URL起作用…?不是我的优点。页面中的内容由一些javascript框架自动生成。为了测试,我只使用了禁用javascript的broser。服务器完成了其余的工作。
http://www.roku.com/channels?_escaped_fragment_=details/12/netflix#!details/12/netflix
Do While IE.Busy Or IE.ReadyState <> 4
WScript.Sleep 100
Loop
Set imgTags = IE.document.getElementsByTagName("IMG")
For Each imgTag In imgTags
imgClass = imgtag.getAttribute("class")
If IsNull( imgClass ) Then
imgClass = imgTag.className
End If
If imgclass = "cs-poster-big" Then
MsgBox "src is " & imgTag.src
End If
Next