当前位置: 动力学知识库 > 问答 > 编程问答 >

vbscript - ie.document.body.innerhtml picking up wrong HTML

问题描述:

When I use the innerHtml property, it seems to be getting the HTML of the form as opposed to the forms output. I'm after the HTML in the resulting table that contains this f_details('277095'); where f_details('num'); represents the license number for each agent on each row. This script navigates to the site, makes a county selection, submits form, and dumps HTML - just not the correct HTML. How can I target at the HTML of the resulting table (the table that appears after form submitted)?

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

The code is modified to dump only 2 pages for testing.

网友答案:

1) you need to exit the For Each loop once you clicked the button.

2) you need to wait until the page finishes loading after pressing the button.

so replace you For Each loop with thie code:

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

side notes:

you don't need to set again fso as a FileSystemObject in your For i loop since you did it already before the loop.

to set the FileName you don't have to create another object since you already created the FileSystemObject in the beginning, so set the FileName BEFORE the For i loop like this:

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

Hope this helps.

分享给朋友:
您可能感兴趣的文章:
随机阅读: