shahin
Active Member
To get the first text embedded within the class mentioned below, we usually follow the below method or anything similar to that:
However, when I try to go like this, it doesn't print anything no error either. What should be the accurate method to accomplish the way I've started below?
Code:
Sub fetch_specific_text()
Dim IE As New InternetExplorer, html As New HTMLDocument
Dim post As Object
With IE
.Visible = True
.navigate "https://stackoverflow.com/questions/"
Do While IE.readyState <> READYSTATE_COMPLETE: Loop
Set html = .document
End With
For Each post In html.getElementsByClassName("summary")(0).getElementsByClassName("excerpt")
Debug.Print post.innerText
Next post
IE.Quit
End Sub
However, when I try to go like this, it doesn't print anything no error either. What should be the accurate method to accomplish the way I've started below?
Code:
Sub fetch_specific_text()
Dim IE As New InternetExplorer, html As New HTMLDocument
Dim post As Object
With IE
.Visible = True
.navigate "https://stackoverflow.com/questions/"
Do While IE.readyState <> READYSTATE_COMPLETE: Loop
Set html = .document
End With
For Each post In html.getElementsByClassName("summary")
If post.className = "excerpt" Then Debug.Print post.innerText: Exit For
Next post
IE.Quit
End Sub