VBA Extracting text from website inspect element

Versonol

New Member
Joined
Jul 10, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi , I'm currently trying to extract the title and dates of each news article in my url range by finding the h1 class "headline node- title" and getting the title based on it.
1668483062640.png

When I try running my code, I get [object HTMLHeadingElement] instead of the title "No new curbs in recent wave..." . Any solution on how to fix it? Here is one of the website I use No new curbs in recent wave, but they cannot be ruled out if new nasty Covid-19 variant hits: Ong Ye Kung
1668483166498.png

Here is my code :
VBA Code:
Private Sub CommandButton5_Click()
Dim URL As String, IE As Object, Count As Integer
Set s1 = Worksheets("Sheet1")
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
Range("A2").Select
Count = 2
While ActiveCell.Value <> ""
URL = ActiveCell.Value
If Count >= 1 Then
IE.Navigate URL
End If
Do While IE.ReadyState = 4: DoEvents: Loop
Do Until IE.ReadyState = 4: DoEvents: Loop
Set ieClassColl = IE.document.body.getElementsByClassName("headline node-title")
s1.Cells(Count, "B") = ieClassColl
Count = Count + 1
ActiveCell.Offset(1, 0).Select
Wend
If ActiveCell = "" Then
IE.Quit
End If
On Error GoTo AppQuit
AppQuit:
MsgBox "Application Closed"

End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Since getElementsByClassName returns a collection, try...

VBA Code:
s1.Cells(Count, "B") = ieClassColl(0).innerText

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,214,789
Messages
6,121,605
Members
449,038
Latest member
Arbind kumar

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