如何获取元名称关键字-vba [英] how to get the meta name keywords -vba
本文介绍了如何获取元名称关键字-vba的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从网页
meta name ="keywords" content =米歇尔·阿尔博姆,再过一天,小布朗书组,0751537535,小说/综合,一般与文学小说,现代与当代小说(1945年后),美国
meta name="keywords" content="Mitch Albom,For One More Day,Little, Brown Book Group,0751537535,Fiction / General,General & Literary Fiction,Modern & contemporary fiction (post c 1945),USA
我需要从中获取内容,需要帮助.
I need to get the contents from it need help.
Option Explicit
Sub GetData()
Dim ie As New InternetExplorer
Dim str As String
Dim wk As Worksheet
Dim webpage As New HTMLDocument
Dim item As HTMLHtmlElement
Set wk = Sheet1
str = wk.Range("Link").value
ie.Visible = True
ie.Navigate str
Do
DoEvents
Loop Until ie.ReadyState = READYSTATE_COMPLETE
Dim Doc As HTMLDocument
Set Doc = ie.Document
Dim kwd As String
kwd = Trim(Doc.getElementsByTagName("keywords").innerText)
MsgBox kwd
End Sub
推荐答案
最好的方法是找到名称为 keyword 的元元素,并引用其content
属性.您可以这样:
The best way to do that is by finding meta-element with name keyword and referring to its content
property. You can do it like that:
Option Explicit
Sub GetData()
Dim ie As New InternetExplorer
Dim str As String
Dim wk As Worksheet
Dim webpage As New HTMLDocument
Dim item As HTMLHtmlElement
Set wk = Sheet1
str = wk.Range("Link").value
ie.Visible = True
ie.Navigate str
Do
DoEvents
Loop Until ie.ReadyState = READYSTATE_COMPLETE
'Find the proper meta element --------------
Const META_TAG As String = "META"
Const META_NAME As String = "keywords"
Dim Doc As HTMLDocument
Dim metaElements As Object
Dim element As Object
Dim kwd As String
Set Doc = ie.Document
Set metaElements = Doc.all.tags(META_TAG)
For Each element In metaElements
If element.Name = META_NAME Then
kwd = element.Content
End If
Next
MsgBox kwd
End Sub
这篇关于如何获取元名称关键字-vba的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文