我正在尝试在<p>
标记内提取span的文本。我的HTML看起来像这样
<p itemprop="address" itemscope itemtype="https://schema.org/PostalAddress">
<span itemprop="streetAddress">
addressline1,line2,town,postalcode
</span>
</p>
我的vba代码是
Dim htmlele1 As HTMLDivElement
For Each htmlele1 In doc.getElementsByTagName("span")
If htmlele1.attributes.itemprop = "streetAddress" Then
Range("c" & i).Value = htmlele1.innerText
End If
Next
但它不起作用。如何获取带有属性
的范围文本答案 0 :(得分:1)
试试这个:
For Each htmlele1 In doc.getElementsByTagName("span")
If htmlele1.getAttribute("itemprop") = "streetAddress" Then
Range("c" & i).Value = htmlele1.innerText
End If
Next