How to get meta data from webpage automatically using VBA. Meta tags are tags like ‘description’, ‘keywords’, etc. that are not displayed on the web page but used by search engines. Watch the video below:
Watch this video on YouTube.
Here’s the complete VBA code to extract the meta tags from web pages like ‘yahoo’, ‘youtube’, etc.
Option Explicit
Sub getMetaData()
Dim ie As New InternetExplorer
Dim myLink As String
Dim wks As Worksheet
Set wks = Sheet1
myLink = wks.Range(“A2”).Value
ie.Visible = True
ie.Navigate myLink
Do
DoEvents
Loop Until ie.ReadyState = READYSTATE_COMPLETE
Const meta_tag As String = “meta”
Const meta_name As String = “keywords”
‘Const meta_name As String = “description”
Dim Doc As HTMLDocument
Dim metaElements As Object
Dim element As Object
Dim keywd As String
Set Doc = ie.Document
Set metaElements = Doc.all.tags(meta_tag)
For Each element In metaElements
If element.Name = meta_name Then
keywd = element.Content
End If
Next
‘MsgBox keywd
Range(“B2”).Value = keywd
Columns(“B”).AutoFit
End Sub
Further reading:
Scraping Web Page Tables Data Using VBA