ie.document.body.innerhtml 捡错了 HTML

ie.document.body.innerhtml picking up wrong HTML

当我使用 innerHtml 属性 时,它似乎正在获取表单的 HTML 而不是表单输出。我在包含此 f_details('277095'); 的结果 table 中的 HTML 之后,其中 f_details('num'); 代表每一行中每个代理的许可证号。此脚本导航到该站点,进行县选择,提交表单,然后转储 HTML - 只是不正确 HTML。如何定位结果 table 的 HTML(提交表单后出现的 table)?

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 个页面以供测试。

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

旁注:

您不需要在 For i 循环中再次将 fso 设置为 FileSystemObject,因为您已经在循环之前设置了它。

要设置 FileName 你不必创建另一个对象,因为你已经在开始时创建了 FileSystemObject,所以在 For i 循环之前设置文件名,就像这样:

FileName = FSO.GetParentFolderName(WScript.ScriptFullName) & "\License.txt"

希望对您有所帮助。