org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/json;charset=UTF-8, URL=
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 org.jsoup.helper.HttpConnection.get(HttpConnection.java:216)
Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/json;charset=UTF-8,
看到这段之后直接定位错误问题,未知 content 类型.
有两个解决办法.
- 在header指定"content-type"字段的类型
- 添加ignoreContentType(true) 直接无视content类型
String res = Jsoup.connect(url)
.ignoreContentType(true)
.get()
.toString();
方法二更好用
Jsoup入门可以看我的另一篇文章 使用Jsoup库编写Java爬虫 Java爬虫库的快速学习入门编写