IUWebBrowser2对象的“繁忙”方法失败

时间:2019-07-18 11:30:05

标签: vba web web-scraping

当我通过代码启动站点时,在变量“ oDoc”级别出现类型为“对象iwebbrowser2的方法文档失败”的错误

Private Function CreerNavigateur(ByVal mails As String)
Dim IE As Object
Dim oDoc As Object
Dim Htable, maTable As Object
Dim text As String
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.navigate "https://csrtool-ssl.sso.infra.ftgroup/csrtool_web/Bricks/pg/osuit/pages/identity/IdentityAccountAndUsers?type=emailAlias&value=" & mails & "&tab_main=AccountInfo"
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
    Set oDoc = IE.Document
    Set Htable = oDoc.getElementsByTagName("div")(1)
   ' MsgBox Htable.innerhtml
    Set maTable = Htable.getElementsByTagName("span")
    'MsgBox maTable(0).href
    'myData = maTable(0).innertext
    'MsgBox (myData)
    IE.Quit
    'On libère les variables
    Set IE = Nothing
    Set oDoc = Nothing
End Function

感谢您帮助我看到我的错误

1 个答案:

答案 0 :(得分:1)

形式化我的答案,尝试最大化,即窗口和更新的代码将

Private Function CreerNavigateur(ByVal mails As String)
    Dim ie As SHDocVw.InternetExplorer
    Dim oDoc As Object
    Dim Htable, maTable As Object
    Dim text As String

    Set ie = New SHDocVw.InternetExplorer
    ie.Visible = False
    ie.navigate "https://csrtool-ssl.sso.infra.ftgroup/csrtool_web/Bricks/pg/osuit/pages/identity/IdentityAccountAndUsers?type=emailAlias&value=" & mails & "&tab_main=AccountInfo"

    While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend

    Set oDoc = ie.Document
    Set Htable = oDoc.getElementsByTagName("div")(1)
    'MsgBox Htable.innerhtml
    Set maTable = Htable.getElementsByTagName("span")
    'MsgBox maTable(0).href
    'myData = maTable(0).innertext
    'MsgBox (myData)
    ie.Quit
    'On libère les variables
    Set ie = Nothing
    Set oDoc = Nothing
End Function