我想获得亚马逊产品的价格,然后将它们放入电子表格中,价格接近时间。我正在尝试使用Jsoup(我对此非常新) 这就是我现在拥有的。 我甚至无法得到价格,所以这是我最需要的帮助
/*
* 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);
}
}
答案 0 :(得分:2)
你在这里遇到的问题很少:
document.select
返回Element
,而不是String
。你的seletor不对。 使用以下代码:
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());