JSOUP内容类型处理
问题描述:
我解析在自动模式下的网页与JSOUP并得到这样的错误: org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=image/jpeg,
JSOUP内容类型处理
至于解决方案,它提供here使用ignoreContentType()函数,将“力jsoup忽略的内容类型并将响应解析为HTML'。我不想来解析图片为HTML,那么有没有什么办法处理此类异常或得到这样的内容类型:
if (Contenttype == 'text' or Contenttype == 'xml' or ...what_ever_other_text_format)
parse
else
do_nothing.
答
使用HttpConnection.Response的方法的contentType获取内容类型,并据此决定
连接.Response res = Jsoup.connect(“http://www.google.com/”).timeout(10 * 1000).execute();
String contentType = res.contentType();