我已经这样做过几次了,但是我不确定为什么这次我的HTA vbscript对我大喊Object不支持这个属性或方法IE.Document.form1?
忽略等待IE,2000 subs。
Function server_details(server_name)
dim returnArray(6)
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://website/Default.aspx"
Wait IE,2000
With IE.Document.form1
.txtServerName.value = server_name
.Button1.click
End With
Wait IE,4000
'get info returned
With IE.Document.all
serverOS = .txtOS.value
serverApp = .txtBusinessApp.value
serverClass = .txtServerClass.value
serverHost = .txtHost.value
serverEnv = .txtSupportEnvironment.value
serverCheckout = .txtCheckoutStatus.value
End With
IE.Quit
Set IE = Nothing
returnArray(0) = serverOS
returnArray(1) = ServerApp
returnArray(2) = serverClass
returnArray(3) = serverHost
returnArray(4) = serverEnv
returnArray(5) = serverCheckout
server_details = returnArray
End Function
我在我的HTA vbscript中也有这个函数,它工作得很好。
Function subnetDetails(server_ip)
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.Navigate "http://otherwebsite/detail.aspx"
Wait IE,2000
With IE.Document.aspnetForm
.[ctl00$_SUMMARY$txtIP].value = server_ip
.[ctl00$_SUMMARY$btnLoad].click
End With
'webscrape for TABLE id="ctl00_SUMMARY_gvSubnets"
Wait IE,9000
responseHTML = IE.Document.getElementByID("ctl00_SUMMARY_gvSubnets").outerHTML
IE.Quit
Set IE = Nothing
subnetDetails = responseHTML
End Function
发现form1在iframe中,这可能是我不能引用它的原因。有什么想法吗?
<iframe id="ctl00_ContentPlaceHolder1_I1" bordercolor="White" name="I1" src="CSIS.aspx" style="border-style: none; overflow: auto; height: 2500px; width: 1100px;" frameborder="no" scrolling="no">
<html>
<head>
<body>
<form name="form1" bla bla"
</iframe>
发布于 2012-09-04 19:56:45
好的,所以我想通了。iframe造成了所有的麻烦。对于那些有相同错误消息的人,请尝试检查表单和元素不是您试图抓取的站点内的iframe的一部分。在站点中使用backwords,获取iframe源代码,并将其放入您的vbscript中,而不是放入您现有的脚本中。
祝你好运!
发布于 2012-09-04 19:19:01
很难忽略你的等待子,因为原因可能就在那里。你似乎使用固定的时间,而你应该使用像这样的东西
Do Until IE.readyState = 4
Wscript.Sleep 100
Loop
此外,在遇到麻烦的情况下,最好将对象级别分开,每行一个,这样更容易调试
With IE
With .document
With ...
然后注释掉,直到它起作用。
这些都是一般的指导原则,如果你发布了真实的URL和你的等待子地址,我们可以给出更直接的建议。
https://stackoverflow.com/questions/12269126
复制