Pull row data from website not working

smccull

New Member
Joined
Jul 26, 2017
Messages
2
Can anyone help with the below, I am trying to pull the data from the table at the following website (all pages 1-7) +Digital – Fund Centre

I have the below code BUT its only pulling through the table headers ... any ideas?


Code:
' return the document containg the DOM of the page strWebAddress
' returns Nothing if the timeout lngTimeoutInSeconds was reached
Public Function GetIEDocument(ByVal strWebAddress As String, Optional ByVal lngTimeoutInSeconds As Long = 15) As MSHTML.HTMLDocument
    Dim IE As SHDocVw.InternetExplorer
    Dim IEDocument As MSHTML.HTMLDocument
    Dim dateNow As Date
    ' create an IE application, representing a tab
    Set IE = New SHDocVw.InternetExplorer
    ' optionally make the application visible, though it will work perfectly fine in the background otherwise
    IE.Visible = True
    ' open a webpage in the tab represented by IE and wait until the main request successfully finished
    ' times out after lngTimeoutInSeconds with a warning
    IE.Navigate strWebAddress
    dateNow = Now
    Do While IE.Busy
        If Now > DateAdd("s", lngTimeoutInSeconds, dateNow) Then Exit Function
    Loop
    ' retrieve the webpage's content (that is, the HTML DOM) and wait until everything is loaded (images, etc.)
    ' times out after lngTimeoutInSeconds with a warning
    Set IEDocument = IE.Document
    dateNow = Now
    Do While IEDocument.ReadyState <> "complete"
        If Now > DateAdd("s", lngTimeoutInSeconds, dateNow) Then Exit Function
    Loop
    Set GetIEDocument = IEDocument
End Function
                    
Public Sub GetTeamData()
    Dim strWebAddress As String
    Dim strH2AnchorContent As String
    Dim IEDocument As MSHTML.HTMLDocument
    Dim objH2 As MSHTML.HTMLHeaderElement
    Dim obTable As MSHTML.HTMLTable
    Dim objRow As MSHTML.HTMLTableRow
    Dim objCell As MSHTML.HTMLTableCell
    Dim lngRow As Long
    Dim lngColumn As Long
    ' initialize some variables that should probably better be passed as paramaters or defined as constants
    strWebAddress = "[url=https://toolkit.financialexpress.net/santanderam]+Digital – Fund Centre[/url]"
   
    dateNow = Now
    bExitLoop = False
    lngTimeoutInSeconds = 5
    Do While Not bExitLoop
      If Now > DateAdd("s", lngTimeoutInSeconds, dateNow) Then Exit Do
    Loop
    
    ' open page
    Set IEDocument = GetIEDocument(strWebAddress)
    If IEDocument Is Nothing Then
        MsgBox "Timeout reached opening this address:" & vbNewLine & strWebAddress, vbCritical
        Exit Sub
    End If
    ' retrieve anchor element
    Set oTable = IEDocument.getElementById("Price_1_1")
    Debug.Print oTable.innerText
    ' iterate over the table and output its contents
    lngRow = 1
    For Each objRow In oTable.Rows
       lngColumn = 1
        For Each objCell In objRow.Cells
            Cells(lngRow, lngColumn) = objCell.innerText
            lngColumn = lngColumn + 1
        Next objCell
        lngRow = lngRow + 1
    Next
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top