2016-11-10 4 views
-1

zu holen Ich möchte die Preise eines Amazon-Produkts erhalten und sie dann in eine Tabelle mit dem Preis neben der Zeit legen. Ich versuche, Jsoup dafür zu verwenden (und ich bin sehr neu dazu) Das ist, was ich derzeit habe. Ich kann nicht einmal den Preis bekommen, so dass ist das, was ich am meisten Hilfe benötigen mitIch versuche Amazon Preise mit Jsoup auf Java

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package amazon; 

/** 
* 
* @author kennethkreindler 
*/ 
import java.io.IOException; 

import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
import org.jsoup.nodes.Element; 
import org.jsoup.select.Elements; 
public class Amazonmain { 

    /** 
    * @param args the command line arguments 
    * @throws java.lang.Exception 
    */ 

    public static void main(String[] args) throws Exception { 
     String url = "http://www.amazon.de/DJI-CP-PT-000498-Mavic-Drohne-grau/dp/B01M0AVO1P/"; 
     Document document = Jsoup.connect(url).userAgent("Mozilla/17.0").get(); 

     String question = document.select("span.priceblock_ourprice"); 
     System.out.println("Price is" + question); 


     } 
    } 
+4

Wie wäre es einfach mit [ihre API] (http://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_RetrievingPriceInformation.html)? – Filburt

Antwort

2

Sie haben einige Probleme hier:

  1. Ihr User-Agent veraltet ist, so dass Sie eine ganz andere Antwort erhalten als du erwartest. Verwenden Sie einen neueren.
  2. document.select gibt eine Element, nicht String zurück.
  3. Ihr Selector ist nicht richtig. Verwenden Sie den folgenden Code ein:

    String url = "http://www.amazon.de/DJI-CP-PT-000498-Mavic-Drohne-grau/dp/B01M0AVO1P/"; 
    Document document = Jsoup.connect(url).userAgent("Mozilla/49.0").get(); 
    Elements question = document.select("#priceblock_ourprice"); 
    System.out.println("Price is " + question.html());