【问题标题】:I am trying to fetch amazon prices using Jsoup on Java我正在尝试在 Java 上使用 Jsoup 获取亚马逊价格
【发布时间】:2016-11-11 05:57:50
【问题描述】:

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


        }
    }

【问题讨论】:

标签: java jsoup amazon fetch


【解决方案1】:

你有几个问题:

  1. 您的用户代理已过时,因此您得到的响应与您预期的完全不同。使用较新的。
  2. document.select 返回 Element,而不是 String
  3. 您的选择器不正确。 使用以下代码:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    相关资源
    最近更新 更多