excel vba表单提交并解析结果中的数据

时间:2013-03-08 18:13:22

标签: html excel parsing vba

这是我的代码,不幸的是对公司问题做了我无法发布真实的网址,它的工作原理但不是我想要的方式,请查看下面的问题:

Dim doc As HTMLDocument
Dim IE As InternetExplorer
Dim TDelements As IHTMLElementCollection
Dim TDelement As HTMLTableCell
Dim r As Long

Sub ficfinder()
Set IE = CreateObject("InternetExplorer.Application")
    With IE
        .Visible = True
        .navigate URL:="...INPUT"<---this is my search form, but i have to redact due to co policy
    Do 'Until .readyState = 4
    DoEvents
    Loop Until IE.readyState = READYSTATE_COMPLETE
    'pick field to fill out
    Set mytextfield1 = .document.all.Item("WESTAC")
    'set value to put in
    mytextfield1.Value = "5416869160"
    'click the submit button
    IE.document.all.Item("Submit").Click
    Do 'Until .readyState = 4
    DoEvents
    Loop Until IE.readyState = READYSTATE_COMPLETE
    End With
'I think i'm missing something here

    Set doc = IE.document
    Dim sdd As String
    Set TDelements = doc.getElementsByTagName("td")
    r = 0
    For Each TDelement In TDelements
        If TDelement.Align = "right" Then
            Sheet2.Range("A1").Offset(r, 0).Value = TDelement.innerText
            r = r + 1
        End If
    Next
End Sub

所以这可以工作并将数据放入我的电子表格中,但它所提取的数据来自搜索表单,而不是您提交后出现的页面。我如何使IE.document成为新的页面?

任何帮助表示感谢,谢谢!

1 个答案:

答案 0 :(得分:0)

我添加了

Do While IE.Busy: DoEvents: Loop

提交后,它完美无缺。感谢Tim Williams的帮助!