当我使用innerHtml
属性时,它似乎是获取表单的HTML而不是表单输出。我在结果表中的HTML之后包含此f_details('277095');
,其中f_details('num');
表示每行上每个代理的许可证号。此脚本导航到站点,进行县选择,提交表单和转储HTML - 只是不正确的HTML。如何定位结果表的HTML(表单提交后出现的表)?
Set objWshShell = Wscript.CreateObject("Wscript.Shell")
Set IE = CreateObject("internetexplorer.application")
Set fso = CreateObject("Scripting.FileSystemObject")
For i=1 To 3 '77 Counties
If i=3 Then Exit For
IE.Visible = True
IE.Navigate "https://lic.ok.gov/PublicPortal/OREC/FindAssociateEntity.jsp"
Do Until IE.ReadyState = 4: WScript.sleep 100: Loop
Do Until IE.Document.ReadyState = "complete": WScript.sleep 100: Loop
IE.Document.getElementsByTagName("select")("AddrCountyCode").Value = i
Do Until IE.Document.ReadyState = "complete": WScript.sleep 100: Loop
For Each btn In IE.Document.getElementsByTagName("input")
If btn.name = "btnSearch" Then btn.Click()
Next
strTestString = ie.document.body.innerhtml
filename = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\License.txt"
Set fso = createobject("scripting.filesystemobject")
Set ts = fso.opentextfile(filename,8,true)
ts.write strTestString
ts.close
Next
修改代码只转储2页进行测试。
答案 0 :(得分:0)
1)单击按钮后,您需要退出For Each
循环。
2)按下按钮后,您需要等到页面完成加载。
所以用你的代码替换你For Each
循环:
For Each btn In IE.Document.getElementsByTagName("input")
If btn.name = "btnSearch" Then
btn.Click
exit for
End If
Next
Do Until IE.Document.ReadyState = "complete": WScript.sleep 100: Loop
旁注:
您不需要在FileSystemObject
循环中再次将fso设置为For i
,因为您已经在循环之前完成了此操作。
设置你不必创建另一个对象的FileName
,因为你已经在开头创建了FileSystemObject
,所以在这样的For i
循环之前设置FileName:< / p>
FileName = FSO.GetParentFolderName(WScript.ScriptFullName) & "\License.txt"
希望这有帮助。