2017-06-03 16 views
0

Welchen Code soll ich verwenden, um Preis von diesem HTML-Code zu extrahieren? Ich möchte Element erhalten entweder durchWebscraping mit VBA Excel

  • Id
  • tagname
  • classname

Website URL: https://www.tatacliq.com/vivo-v5-32gb-gold-4-gb-ram-dual-sim-4g/p-mp000000000734559

Sagen wir, ich möchte unten für "Preis" Daten abzurufen HTML (dh erhalte "14999"):

Hier ist mein Code:

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 

[Platzhalter zu erklären, was zur Zeit falsch mit meinem Code wird]

+2

Sie veröffentlichen sollten Ihre Code/Bemühungen und wir sollten mit Ihren Fehlern/Fehlern umgehen. Nicht viele werden einen Code für Sie schreiben, um den Preis zu erhalten. – Tehscript

+0

Entschuldigung, dass ich den Code nicht gepostet habe. Bitte überprüfen Sie jetzt, ich habe die Frage aktualisiert –

+0

'objIE.Document.getElementsByClassName (" Verkauf ") (1)' ist ein Weg, 'objIE.Document.getElementById (" spPriceId ") ist ein anderer. Sie sollten den Quellcode überprüfen, und Sie werden sehen, dass der Rest einfach ist. – Tehscript

Antwort

0

Es ist etwas passiert mit Javascript, die ich nicht verstehen kann, und könnte ändern Sie die Art, wie Sie Ihr Ding verschrotten können.

Hier ist es möglich, den Preis mit outertext zu kratzen, wenn Sie objIE.Document.getElementById("spPriceId") haben:

Function Scraptatacliq(tatacliq_url As String) 
    Scraptatacliq = "" 
    If tatacliq_url = "" Then Exit Function 
    the_display_price = "" 
    the_display_seller = "" 

the_start: 
    Dim objIE As Object 
    Set objIE = CreateObject("InternetExplorer.Application") 
    objIE.Top = 0 
    objIE.Left = 0 
    objIE.Height = 800 
    objIE.Navigate (tatacliq_url) 

    Do 
    DoEvents 
    If Err.Number <> 0 Then 
     objIE.Quit 
     Set objIE = Nothing 
     GoTo the_start: 
    End If 
    Loop Until objIE.ReadyState = 4 

    objIE.Visible = True 
    Set the_input_element = objIE.Document.getElementById("spPriceId") 
    product_display_price = the_input_element.outertext 
    MsgBox product_display_price 

End Function 

Eine andere Lösung könnte sauberer sein, wenn Sie sehen, was passiert, wenn Sie Javascript deaktivieren