VBA挂在ie.busy和的readyState检查 [英] VBA hanging on ie.busy and readystate check

查看:3793
本文介绍了VBA挂在ie.busy和的readyState检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从网站抓住一些足球运动员的数据,以填补私人使用的数据库。我已经包括下面的整个code。这第一个部分是一个活套调用第二个函数来填充数据库。我碰到这个code在MSACCESS填补数据库,去年夏天和它的工作太棒了。

现在,我只得到了几支球队,以填补前的节目被挂起来的

 虽然IE.Busy或者IE.ReadyState<> READYSTATE_COMPLETE:调用DoEvents:WEND
 

我搜索关于此错误无数的网站,并试图通过将在子功能等待一段秒或其他变通改变这个code。这些都不解决问题。我也试着在多台计算机上运行这一点。

第一台计算机通过3支球队(或第二功能的三个调用)做到了。第二慢的电脑使得它到5支球队。双方最终挂起。的第一计算机具有的Internet Explorer 10和第二有IE8。

 子Parse_NFL_RawSalaries()

    状态(导入NFL薪资信息。)
    昏暗的MYDB数据库
    昏暗teamdata作为DAO.Recordset
    昏暗我作为整数
    昏暗Ĵ作为双

    一系列mydb = CurrentDb()
    设置teamdata = mydb.OpenRecordset(团队)

    I = 1
    随着teamdata
        做直到.EOF
            呼叫Parse_Team_RawSalaries(teamdata![RotoworldTeam])
            .MoveNext
            I = I + 1
            J = / 32
           状态(导入NFL薪资信息。&放大器; STR(圆(j * 100,0))及%完成)
        循环
   结束与

  重置变量
  teamdata.Close
  设置teamdata =什么
  一系列mydb =什么

  状态(),复位状态栏

结束小组
 

Seconnd功能:

 功能Parse_Team_RawSalaries(队作为字符串)

    昏暗的MYDB数据库
    昏暗首先作为DAO.Recordset
    昏暗即作为InternetExplorer的
    昏暗HTMLDOC作为HTMLDocument的
    昏暗TABLEelements作为IHTMLElementCollection
    昏暗TRelements作为IHTMLElementCollection
    昏暗TDelements作为IHTMLElementCollection
    昏暗TABLEelement作为对象
    昏暗TRelement作为对象
    昏暗TDelement作为HTMLTableCell
    尺寸C只要

   打开表
   一系列mydb = CurrentDb()
   设置RST = mydb.OpenRecordset(TempSalary)

   设置IE =的CreateObject(InternetExplorer.Application)
   IE.Visible = FALSE
   IE.navigatehttp://www.rotoworld.com/teams/contracts/nfl/与&球队
   虽然IE.Busy或者IE.ReadyState<> READYSTATE_COMPLETE:调用DoEvents:WEND
   设置HTMLDOC = IE.Document

   设置TABLEelements = HTMLdoc.getElementsByTagName(表)
   对于每个TABLEelement在TABLEelements
       如果TABLEelement.id =cp1_tblContracts然后
            设置TRelements = TABLEelement.getElementsByTagName(TR)
            对于每个TRelement在TRelements
                如果TRelement.className<> columnnames那
                    rst.AddNew
                    RST![队伍] =队
                    C = 0
                    设置TDelements = TRelement.getElementsByTagName(TD)
                    对于每个TDelement在TDelements
                        选择情况c
                            案例0
                                RST![播放] =修剪(TDelement.innerText)
                            情况1
                                RST![位置] =修剪(TDelement.innerText)
                            案例2
                                RST![ContractTerms] =修剪(TDelement.innerText)
                        最终选择
                        C = C + 1
                    接下来TDelement
                    rst.Update
              结束如果
          接下来TRelement
      结束如果
  接下来TABLEelement
  重置变量
  rst.Close
  第一个设置=什么
  一系列mydb =什么

  IE.Quit


端功能
 

解决方案

Parse_Team_RawSalaries ,而不是使用 InternetExplorer.Application 对象,如何使用 MSXML2.XMLHTTP60

因此​​,而不是这样的:

 设置IE =的CreateObject(InternetExplorer.Application)
IE.Visible = FALSE
IE.navigatehttp://www.rotoworld.com/teams/contracts/nfl/与&球队
虽然IE.Busy或者IE.ReadyState<> READYSTATE_COMPLETE:调用DoEvents:WEND
设置HTMLDOC = IE.Document
 

也许尝试使用这个(添加一个引用到VBA编辑器中的Microsoft XML 6.0在前):

 昏暗的IE浏览器作为MSXML2.XMLHTTP60
设置IE =新MSXML2.XMLHTTP60

IE.OpenGET,http://www.rotoworld.com/teams/contracts/nfl/&放大器;团队,假
IE.send

虽然IE.ReadyState<> 4
    的DoEvents
蜿蜒

昏暗HTMLDOC作为MSHTML.HTMLDocument
昏暗HTMLBody作为MSHTML.htmlBody

设置HTMLDOC =新MSHTML.HTMLDocument
设置HTMLBody = HTMLDoc.body
HTMLBody.innerHTML = IE.responseText
 

我通常发现, MSXML2.XMLHTTP60 (和 WinHttp.WinHtt prequest ,该物)通常表现得更好(更快,更可靠),比 InternetExplorer.Application

I am trying to grab some football player data from a website to fill a privately used database. I've included the entire code below. This first section is a looper that calls the second function to fill a database. I've run this code in MSAccess to fill a database last summer and it worked great.

Now I am only getting a few teams to fill before the program gets hung up at

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

I've searched countless websites regarding this error and tried changing this code by putting in sub function to wait a period of seconds or other work arounds. None of those solve the issue. I've also tried running this on multiple computers.

The first computer made it through 3 teams (or three calls of the 2nd function). The second slower computer makes it through 5 teams. Both eventually hang. The 1st computer has Internet Explorer 10 and the second has IE8.

Sub Parse_NFL_RawSalaries()

    Status ("Importing NFL Salary Information.")
    Dim mydb As Database
    Dim teamdata As DAO.Recordset
    Dim i As Integer
    Dim j As Double

    Set mydb = CurrentDb()
    Set teamdata = mydb.OpenRecordset("TEAM")

    i = 1
    With teamdata
        Do Until .EOF
            Call Parse_Team_RawSalaries(teamdata![RotoworldTeam])
            .MoveNext
            i = i + 1
            j = i / 32
           Status ("Importing NFL Salary Information. " & Str(Round(j * 100, 0)) & "% done")
        Loop
   End With

  ' reset variables
  teamdata.Close
  Set teamdata = Nothing
  Set mydb = Nothing

  Status ("")                  'resets the status bar

End Sub

Seconnd function:

Function Parse_Team_RawSalaries(Team As String)

    Dim mydb As Database
    Dim rst As DAO.Recordset
    Dim IE As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    Dim TABLEelements As IHTMLElementCollection
    Dim TRelements As IHTMLElementCollection
    Dim TDelements As IHTMLElementCollection
    Dim TABLEelement As Object
    Dim TRelement As Object
    Dim TDelement As HTMLTableCell
    Dim c As Long

   ' open the table
   Set mydb = CurrentDb()
   Set rst = mydb.OpenRecordset("TempSalary")

   Set IE = CreateObject("InternetExplorer.Application")
   IE.Visible = False
   IE.navigate "http://www.rotoworld.com/teams/contracts/nfl/" & Team
   While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
   Set HTMLdoc = IE.Document

   Set TABLEelements = HTMLdoc.getElementsByTagName("Table")
   For Each TABLEelement In TABLEelements
       If TABLEelement.id = "cp1_tblContracts" Then
            Set TRelements = TABLEelement.getElementsByTagName("TR")
            For Each TRelement In TRelements
                If TRelement.className <> "columnnames" Then
                    rst.AddNew
                    rst![Team] = Team
                    c = 0
                    Set TDelements = TRelement.getElementsByTagName("TD")
                    For Each TDelement In TDelements
                        Select Case c
                            Case 0
                                rst![Player] = Trim(TDelement.innerText)
                            Case 1
                                rst![position] = Trim(TDelement.innerText)
                            Case 2
                                rst![ContractTerms] = Trim(TDelement.innerText)
                        End Select
                        c = c + 1
                    Next TDelement
                    rst.Update
              End If
          Next TRelement
      End If
  Next TABLEelement
  ' reset variables
  rst.Close
  Set rst = Nothing
  Set mydb = Nothing

  IE.Quit


End Function

解决方案

In Parse_Team_RawSalaries, instead of using the InternetExplorer.Application object, how about using MSXML2.XMLHTTP60?

So, instead of this:

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.navigate "http://www.rotoworld.com/teams/contracts/nfl/" & Team
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set HTMLdoc = IE.Document

Maybe try using this (add a reference to "Microsoft XML 6.0" in VBA Editor first):

Dim IE As MSXML2.XMLHTTP60
Set IE = New MSXML2.XMLHTTP60

IE.Open "GET", "http://www.rotoworld.com/teams/contracts/nfl/" & Team, False
IE.send

While IE.ReadyState <> 4
    DoEvents
Wend

Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLBody As MSHTML.htmlBody

Set HTMLDoc = New MSHTML.HTMLDocument
Set HTMLBody = HTMLDoc.body
HTMLBody.innerHTML = IE.responseText 

I've generally found that MSXML2.XMLHTTP60 (and WinHttp.WinHttpRequest, for that matter) generally perform better (faster and more reliable) than InternetExplorer.Application.

这篇关于VBA挂在ie.busy和的readyState检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆