0
我应该使用哪些代码来从此HTML代码中提取价格?我想通过使用VBA的网页扫描excel
- 编号
- 标记名
- 类名要么得到元素
网址:https://www.tatacliq.com/vivo-v5-32gb-gold-4-gb-ram-dual-sim-4g/p-mp000000000734559
比方说,我要为“价格”获取数据在下面HTML(即得到这个“14999”):
<h3 class="company author">
</h3>
<div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer"
class="price">
<p class="old" id="mrpPriceId" style="display:none">
</p>
<p class="sale" id="mopPriceId" style="display:none">
</p>
<p class="sale" id="spPriceId" style="display:none">
<!-- For TPR-4358 Start -->
<span itemprop="price">14999.00</span>
<span itemprop="priceCurrency">INR</span>
<meta itemprop="itemCondition" content="http://schema.org/NewCondition"
/>
<meta itemprop="availability"
content="http://schema.org/InStock"/>Available online</meta>
<!-- For TPR-4358 End -->
</p>
<p class="savings pdp-savings" id="savingsOnProductId"
style="display:none">
<span></span>
</p>
<br>
这里是我的代码:
Function Scraptatacliq(tatacliq_url As String, the_display_price As String, the_display_seller As String)
''MsgBox "Inside the function"
'Dim objIE As New InternetExplorerMedium
Scraptatacliq = ""
If tatacliq_url = "" Then Exit Function
the_display_price = ""
the_display_seller = ""
'MsgBox tatacliq_url
the_start:
Dim objIE As Object
Set objIE = CreateObject("InternetExplorer.Application")
'Set objIE = New InternetExplorerMedium
objIE.Top = 0
objIE.Left = 0
objIE.Height = 800
'objIE.Visible = True
objIE.Navigate (tatacliq_url)
'MsgBox tatacliq_url
Do
DoEvents
If Err.Number <> 0 Then
objIE.Quit
Set objIE = Nothing
GoTo the_start:
End If
Loop Until objIE.ReadyState = 4
'Loop
Count = 500000
Do
If Count <> 0 Then
Count = Count - 1
End If
Loop Until Count = 0
'EXTRACT DISPLAY PRICE
'On Error Resume Next
'MsgBox "I am about to extract display price"
Set the_input_element = objIE.Document.getElementById("spPriceId").getElementsbyTagName("price")
product_display_price = the_input_element.innertext
'MsgBox product_display_price
'If product_display_price = "" Then
' Set the_input_element =
objIE.Document.getElementById("product_list_price")
' product_display_price = the_input_element.innertext
'End If
[预留解释什么是目前我的代码脚麻]
你应该张贴会发生什么你代码/努力,我们应该处理你的错误/错误。没有多少人会为你写代码来获取价格。 – Tehscript
对不起,我没有发布代码。请检查现在,我已更新问题 –
'objIE.Document.getElementsByClassName(“sale”)(1)'是一种方法,'objIE.Document.getElementById(“spPriceId”)'是另一种方法。你应该检查源代码,你会看到其余的很容易。 – Tehscript