Aurelius M
New Member
- Joined
- May 24, 2020
- Messages
- 2
- Office Version
- 2016
- Platform
- Windows
I need some help from the smart guys here on the site. The code snippet below don't give any errors and it looks that it works fine, but the TD element collection stays empty and the innerText is empty too. That while the data are showing in a visual browser as You can see in the image below. getElementsByTagName don't catch TDelements from the web table, and I can't figure out why ....
Thanks in advance.
Code:
Sub Extract_TD_Text()
Dim URL As String
Dim wMatrix As String
Dim Search As String
Dim IE As InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim myTable As HTMLObjectElement
Dim TDelements As IHTMLElementCollection
Dim TDelement As HTMLTableCell
Dim rij As Long
Dim bGetNext As Boolean
URL = "https://www.nasdaq.com/market-activity/stocks/arch"
wMatrix = "sector;industry;1 year target;forward p/e 1 yr.;earnings per share(eps);annualized dividend;ex dividend date;beta"
Set IE = New InternetExplorer
With IE
.Navigate2 URL
.Visible = False 'or True it don't matter
'Wait for page to load
While .Busy Or .ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
rij = 0
bGetNext = False
Set HTMLdoc = .Document
If HTMLdoc.getElementsByTagName("table")(0).getAttribute("class") = "summary-data__table" Then
Set myTable = HTMLdoc.getElementsByTagName("table")(0)
Set TDelements = myTable.getElementsByTagName("td")
For Each TDelement In TDelements
Search = LCase(Trim(TDelement.innerText))
If Search = "" Then
Search = "Nothing Found"
Else
Search = "*" & Search & "*"
End If
If bGetNext = True Then
Debug.Print TDelement.innerText 'Catch the data from the TDelement
bGetNext = False
End If
'Debug.Print TDelement.className '- useful for inspecting the HTML info
If wMatrix Like Search Then
Debug.Print TDelement.innerText 'Show the string where searching for
bGetNext = True 'Trigger to catch the data from the next TDelement
End If
rij = rij + 1
Next
End If
End With
IE.Quit
End Sub
Thanks in advance.