【问题标题】:Using Jsoup to access HTML but receives error code 503使用 Jsoup 访问 HTML 但收到错误代码 503
【发布时间】:2016-10-08 15:05:30
【问题描述】:

我一直在尝试访问 KissAnime 但是,我一直收到此错误:

org.jsoup.HttpStatusException:获取 URL 的 HTTP 错误。状态=503

当我尝试另一个 URL 时,例如。 https://www.google.com/,效果很好。

这是我的异步任务代码:

 @Override
    protected Void doInBackground(Void... params) {
        try {
            // Connect to the web site
            Document document = Jsoup.connect("https://kissanime.to/AnimeList/")
                    .ignoreContentType(true)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1")
                    .referrer("http://www.google.com")
                    .timeout(12000)
                    .followRedirects(true)
                    .get();
            // Get the html document title
            title = document.title();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

知道如何解决这个问题吗?

【问题讨论】:

  • 我认为动机是反DoS工具they adopted(查看cf_clearance cookie)。

标签: java android html jsoup


【解决方案1】:

要摆脱 503,下面的代码会很有用。

   public static void main(String[] args) throws IOException {
        //This will get you out of Http 503
        Document document = Jsoup.connect("https://kissanime.to/AnimeList/")
                .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 Firefox/49.0").ignoreHttpErrors(true).followRedirects(true).timeout(100000).ignoreContentType(true).get();
        System.out.println(document.body());
}

【讨论】:

    猜你喜欢
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 2019-08-12
    • 2010-10-15
    • 1970-01-01
    相关资源
    最近更新 更多