jsoup抓取網頁報錯UnsupportedMimeTypeException

 

  今天在用Jsoup爬蟲的時候兩次遇到下面錯誤html

Exception in thread "main" org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/json;charset=utf-8, URL=http://qiaoliqiang.cn/Exam/user_login.action
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:600)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:540)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:227)
    at cn.qlq.craw.Jsoup.JsoupCookieCraw.login(JsoupCookieCraw.java:51)
    at cn.qlq.craw.Jsoup.JsoupCookieCraw.main(JsoupCookieCraw.java:24)

 

 

第一次:

代碼:java

Response res = connect.method(Method.POST).execute();// 執行請求

 

 

解決辦法:json

Response res = connect.ignoreContentType(true).method(Method.POST).execute();// 執行請求

 

 

第二次:

代碼:app

        String url = "http://qiaoliqiang.cn/Exam/user_login.action";
        // 直接獲取DOM樹
        Document document = Jsoup.connect(url).post();

 

 

解決辦法:post

        // 直接獲取DOM樹
        Document document = Jsoup.connect(url).ignoreContentType(true).post();
相關文章
相關標籤/搜索