Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Jsoup to access HTML but receives error code 503

I have been trying to access KissAnime however, i kept receiving this error:

org.jsoup.HttpStatusException: HTTP error fetching URL. Status=503

When i tried another URL eg. https://www.google.com/, it works perfectly.

This is my asynctask code:

 @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;
    }

Any idea how to solve this problem?

like image 719
Kelvin Ding Avatar asked Nov 08 '22 13:11

Kelvin Ding


1 Answers

To get rid of 503, below code would be useful.

   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());
}
like image 66
Ramasamy Kasiviswanathan Avatar answered Nov 14 '22 22:11

Ramasamy Kasiviswanathan