• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Increase speed to Extract Data from Webpage

Hello All,

Can anyone help to increase speed to Extract Data from Webpage, i am using below code and it is taking a very long time.

*****
Code:
Sub newGrabLastNames()

    'dimension (set aside memory for) our variables
    Dim HTMLDoc As New HTMLDocument
    Dim nWB As Workbook
    Dim nWs As Worksheet
    Dim objIE As InternetExplorer
    Dim oIE As InternetExplorer
    Dim ele As Object
    Dim link As Object
    Dim y As Integer
      Dim lngTable As Long
    Dim LngRow As Long, d As Long, Lastrow As Long
    Dim lngCol As Long
    Dim ActRw As Long
    Dim myValue As Variant
    Dim lValue As Variant
    Dim XMLHTTP As Object
   
    Set nWB = Workbooks.Application.ThisWorkbook
   
      Set nWs = nWB.Sheets("Sheet1")
    'start a new browser instance
    Set objIE = New InternetExplorerMedium
    'make browser visible
    objIE.Visible = False
   
    Lastrow = nWs.Cells(Rows.Count, "K").End(xlUp).Row
For d = 2 To Lastrow
   
    myValue = nWB.Sheets("Sheet1").Cells(d, 13).Value
   
   
    'navigate to page with needed data
    objIE.Navigate "google.com"
    'wait for page to load
   

    Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop
    
Application.Wait Now + TimeSerial(0, 0, 10)

Set objcollection = objIE.Document.getElementsByTagName("img")
   
   i = 0
    While i < objcollection.Length
        If objcollection(i).Name = "imgclaimItemInformation" Then

            objcollection(i).Click
            End If
   
i = i + 1
    Wend
   
Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop
Application.Wait Now + TimeSerial(0, 0, 10)
HTMLDoc.body.innerHTML = objIE.Document.body.innerHTML
    With HTMLDoc.body
Set objTable = objIE.Document.getElementById("claimItemInformationDiv"). _
      getElementsByTagName("tbody")
        For lngTable = 0 To objTable.Length - 1
            For LngRow = 0 To objTable(lngTable).Rows.Length - 1
                For lngCol = 0 To objTable(lngTable).Rows(LngRow).Cells.Length - 1
                nWB.Sheets("Sheet2").Select
                    nWB.Sheets("Sheet2").Cells(ActRw + LngRow + 1, lngCol + 1) = objTable(lngTable).Rows(LngRow).Cells(lngCol).innerText
                Next lngCol
            Next LngRow
            ActRw = ActRw + objTable(lngTable).Rows.Length + 1
        Next lngTable
    End With
   
    Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop
Application.Wait Now + TimeSerial(0, 0, 10)

End Sub
******
 
Last edited by a moderator:
Hi,​
as piloting IE requires synchronization with the webpage loading and if the procedure runs faster​
nothing could be extracted, the reason why it must be slow, in particular with a Google webpage …​
 
Back
Top