VBA Internet Explorer 数据提取
VBA internet explorer data extract
我有一个 VBA 宏,我通过它访问 IE。然后,我使用 doc.getElementsByTagName("a") 遍历站点上的所有 link,对于每个 link,我能够提取:
.内文
。班级名称
。ID
.href
.title
但是,当我在 Internet Explorer 中检查 "Inspect Element" 时,"a" 标签中列出了其他数据点。
我感兴趣的两个项目名为 "data-articletypeid" 和 "data-researchid." 我将如何提取这些值?它们似乎是该网站的独特物品。
谢谢,
循环遍历<a>
标签的元素,然后循环遍历元素的属性,通过nodeName
.
提取属性名
Dim elements, element, attr
Dim item As String
Set elements = ie.Document.GetElementsByTagName("a")
For Each element In elements
For Each attr In element.Attributes
Debug.Print attr.nodeName
Next attr
Next element
"The Element interface represents an element in an HTML or XML document. Elements may have attributes associated with them; since the Element interface inherits from Node, the generic Node interface attribute attributes may be used to retrieve the set of all attributes for an element..."
https://msdn.microsoft.com/en-us/library/hh869681(v=vs.85).aspx
我有一个 VBA 宏,我通过它访问 IE。然后,我使用 doc.getElementsByTagName("a") 遍历站点上的所有 link,对于每个 link,我能够提取: .内文 。班级名称 。ID .href .title
但是,当我在 Internet Explorer 中检查 "Inspect Element" 时,"a" 标签中列出了其他数据点。 我感兴趣的两个项目名为 "data-articletypeid" 和 "data-researchid." 我将如何提取这些值?它们似乎是该网站的独特物品。
谢谢,
循环遍历<a>
标签的元素,然后循环遍历元素的属性,通过nodeName
.
Dim elements, element, attr
Dim item As String
Set elements = ie.Document.GetElementsByTagName("a")
For Each element In elements
For Each attr In element.Attributes
Debug.Print attr.nodeName
Next attr
Next element
"The Element interface represents an element in an HTML or XML document. Elements may have attributes associated with them; since the Element interface inherits from Node, the generic Node interface attribute attributes may be used to retrieve the set of all attributes for an element..."
https://msdn.microsoft.com/en-us/library/hh869681(v=vs.85).aspx