0

示例页面:http ://www.amazon.com/gp/offer-listing/1589942140

public void connect( String url ) {        
    this.conn = Jsoup.connect( url );  
}

/**
 * Executes the request and parses the result.
 * @return 
 */
public boolean parse() 
{
    try {
        this.page = this.conn.get();
        return true;
    } catch (IOException ex) {
        // log it here
        System.out.format("Error: %s%n", ex);
        return false;
    }
}    

解析页面会在下面创建 ioexception:

org.jsoup.HttpStatusException:获取 URL 的 HTTP 错误。状态=204,URL= http://www.amazon.com/gp/offer-listing/1589942140

我用下面的本机 java url 类尝试了它,它没有创建 IOException:

    try {
        URL myURL = new URL("http://www.amazon.com/gp/offer-listing/1589942140");
        URLConnection myURLConnection = myURL.openConnection();
        myURLConnection.connect();
        System.out.format("%s", myURLConnection.getContentType());
    } 
    catch (MalformedURLException e) { 
        // new URL() failed
        System.out.format("Error: %s%n", e);
    } 
    catch (IOException e) {   
        // openConnection() failed
        System.out.format("Error: %s%n", e);
    }

任何想法为什么会这样?

4

1 回答 1

0

以下对我有用:

            System.out.println(Jsoup.connect("http://www.amazon.com/gp/offer-listing/1589942140").userAgent("Mozilla").get().text());;

上面尝试的 URL 是您在上面指定的。(示例页面:http ://www.amazon.com/gp/offer-listing/1589942140 )

于 2013-04-05T12:15:26.897 回答