Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我正在尝试使用Java上的Jsoup获取amazon价格_Java_Jsoup_Amazon_Fetch - Fatal编程技术网

我正在尝试使用Java上的Jsoup获取amazon价格

我正在尝试使用Java上的Jsoup获取amazon价格,java,jsoup,amazon,fetch,Java,Jsoup,Amazon,Fetch,我想得到亚马逊产品的价格,然后将其放入电子表格中,并将价格放在时间旁边。我正在尝试为此使用Jsoup(我对此非常陌生) 这就是我现在拥有的。 我甚至不能得到价格,所以这是我最需要的帮助 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the

我想得到亚马逊产品的价格,然后将其放入电子表格中,并将价格放在时间旁边。我正在尝试为此使用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);


        }
    }

您在这里没有什么问题:

  • 您的用户代理已经过时,因此您得到的响应与预期完全不同。用一个新的
  • 文档。选择
    返回一个
    元素
    ,而不是
    字符串
  • 你的选择是不对的。 使用以下代码:

    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());
    

  • 您在这里没有什么问题:

  • 您的用户代理已经过时,因此您得到的响应与预期完全不同。用一个新的
  • 文档。选择
    返回一个
    元素
    ,而不是
    字符串
  • 你的选择是不对的。 使用以下代码:

    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());
    
  • 简单使用怎么样?简单使用怎么样?