使用vba在<p>中获取跨文本
我正在尝试提取<p>
标签内的跨度文本。 我的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
但它不工作。 我如何获取带有属性的跨文本
尝试这个:
For Each htmlele1 In doc.getElementsByTagName("span") If htmlele1.getAttribute("itemprop") = "streetAddress" Then Range("c" & i).Value = htmlele1.innerText End If Next