今天在用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();