【问题标题】:JSOUP content type handling [duplicate]JSOUP 内容类型处理 [重复]
【发布时间】:2014-05-12 00:29:06
【问题描述】:

我正在使用 JSOUP 在自动模式下解析网页并得到这样的错误: org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=image/jpeg,

作为解决方案,here 提供了使用 ignoreContentType() 函数,该函数将“强制 jsoup 忽略内容类型并将响应解析为 HTML”。我不想将图片解析为 HTML,所以有什么方法可以处理此类异常或获取内​​容类型,例如:

if (Contenttype == 'text' or Contenttype  == 'xml' or ...what_ever_other_text_format)
   parse
else
   do_nothing.

【问题讨论】:

    标签: java jsoup


    【解决方案1】:

    使用 HttpConnection.Response 的方法 contentType 获取内容类型并据此决定

    Connection.Response res = Jsoup.connect("http://www.google.com/").timeout(10*1000).execute();

    String contentType=res.contentType();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多