【问题标题】:jsoup crawler error when called inside a servlet在 servlet 中调用 jsoup 爬虫错误
【发布时间】:2015-03-03 12:02:06
【问题描述】:

我正在尝试抓取 Flipkart 产品规格,当我将其作为 Java 应用程序运行时,代码运行良好。但是当我在 servlet 中调用它时,它给了我一个错误:

org.jsoup.nodes.Document doc;

Elements specs = null;

try {
    doc = Jsoup.connect(link).timeout(250000).get();
    specs = doc.select("table[class=specTable]");

    System.out.println(specs);

} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

错误:

java.io.IOException: 500 error loading URL http://www.......
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:414)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:425)

【问题讨论】:

  • 您是否尝试设置 userAgent?
  • 是的。如果我提供一些其他的 Flipkart 链接,例如“flipkart.com”作为链接字符串,它就可以工作,但不适用于此页面。
  • 用您使用的 userAgent 更新您的问题

标签: java google-app-engine servlets web-crawler jsoup


【解决方案1】:

当我使用 userAgent mozilla 时工作。

doc3 = Jsoup.connect(link).userAgent("Mozilla").timeout(250000).get();

【讨论】:

    猜你喜欢
    • 2018-09-11
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多