【发布时间】:2018-12-17 09:59:35
【问题描述】:
我有以下 html 部分
<div>
<p class="wholesaletext"> Χονδρική Τιμή: <br/>
<span id="our_price_display" class="price" itemprop="price" content="9.9">
<p class="wholesaletext">9,90 €
</span> χωρίς Φ.Π.Α
<meta itemprop="priceCurrency" content="EUR" />
</p>
</p>
</div>
我正在尝试使用以下内容从上面获取<p class=wholesaletext"> 的文本
Set price = ie.Document.getElementsByTagName("span")
Dim lnk As Variant
For Each lnk In price
If lnk.className = "price" Then
wks.Cells(i, "E").Value = lnk.innerText
Exit For
End If
Next
我在单元格中什么都没有。
我试过了
Set price = ie.Document.querySelector(".price .wholesaletext")
wks.Cells(i, "E").Value = price.innerText
我什么也得不到。
我试过了
Set price = ie.Document.getElementsByTagName("p")
Dim lnk As Variant
For Each lnk In price
If lnk.className = "wholesale" Then
wks.Cells(i, "E").Value = lnk.innerText
Exit For
End If
Next
但它在 html 中得到另一个文本,而不是价格。
【问题讨论】:
-
试试 .wholesaletext 并等待
标签: excel vba web-scraping