2014-04-01 89 views
0

我解析在自動模式下的網頁與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. 

回答

1

使用HttpConnection.Response的方法的contentType獲取內容類型,並據此決定

連接.Response res = Jsoup.connect(「http://www.google.com/」).timeout(10 * 1000).execute();

String contentType = res.contentType();

相關問題