Webscraping several tables with getElementsByClassName

MLUY

New Member
Joined
Apr 27, 2020
Messages
2
Office Version
  1. 365
Hello there,

I have a basic knowledge of VBA but webscraping, javascript etc is completely new for me.
I have been trying to figure out how to extract (3) tables from the following url: Export Fundamental Data U.S. and International Stocks - QuickFS.net
Through a dropdown I need to get to the Incomestatement, Balance sheet and Cashflow Statement
When I inspect the elements I think below html / javascript statement (s) is the key.

Income Statement <table class="fs-table" id="is-table">
Balance Sheet <table class="fs-table" id="bs-table">
Cashflow Statement <table class="fs-table" id="cf-table">

The table class remains the same whilst the id refers to the different statements

I managed some code to access the Income Statement, but I can not figure out how to get to the others

I would really appreciate if anybody can help me out here
--------------------------------------------------------------------------------------------------------------
Sub GetQuickfs()
Dim IE As New InternetExplorer, html As HTMLDocument
Dim elem As Object, data As String
webaddress = "Export Fundamental Data U.S. and International Stocks - QuickFS.net"

With IE
.Visible = False
.navigate webaddress
Do While .readyState <> READYSTATE_COMPLETE: Loop
Set html = .document
End With

For Each elem In html.getElementsByClassName("fs-table")(0).getElementsByTagName("td")

data = elem.innerText
Debug.Print data
Next elem
IE.Quit
End Sub

------------------------------------------------------------------------------------------------------------------------------------------------
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try getElementById, for example:
VBA Code:
    Dim table As HTMLTable, tRow As HTMLTableRow, tCell As HTMLTableCell
    Set table = html.getElementById("is-table")
    Debug.Print table.innerText
    For Each tRow In table.Rows
        For Each tCell In tRow.Cells
            Debug.Print tCell.innerText; " ";
        Next
        Debug.Print
    Next
 
Upvote 0
Thanks for your response, I tried your code but the table object is empty
 
Upvote 0
By 'empty' do you mean Nothing?

Try replacing the Set table line with:
VBA Code:
    Do
        Set table = HTMLdoc.getElementById("is-table")
        DoEvents
    Loop While table Is Nothing
 
Upvote 0

Forum statistics

Threads
1,223,639
Messages
6,173,498
Members
452,516
Latest member
druck21

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