Jsoup獲取部分頁面數據失敗 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/
阿新 • • 發佈:2018-10-23
mat 博文 get text conn exce res ... 獲取 }
能看到我這裏設置了請求代理和相應時間。
報錯信息如下:
org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/javascript, URL=....
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:472)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:167)
at calendarSpider.SpiderTest.testOuGuanMatch(SpiderTest.java:174)
at calendarSpider.SpiderTest.main(SpiderTest.java:39)
在google上查找到了解決方法:添加ignoreContentType(true)
修改後代碼:
private static void testOuGuanMatch() throws IOException{
Document doc = Jsoup.connect("我的URL").ignoreContentType(true).userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)").timeout(5000).get();
System.out.println(doc);
}
那這裏的ignoreContentType(true)看詞就知道忽略ContextType的檢查
---------------------
作者:就算曾經遍體鱗傷也要相信明天
來源:CSDN
原文:https://blog.csdn.net/u010177899/article/details/68061324
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
用Jsoup在獲取一些網站的數據時,起初獲取很順利,但是在訪問某浪的數據是Jsoup報錯,應該是請求頭裏面的請求類型(ContextType)不符合要求。
請求代碼如下:
private static void testOuGuanMatch() throws IOException{
Document doc = Jsoup.connect("我的URL").userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)").timeout(5000).get();
System.out.println(doc);
能看到我這裏設置了請求代理和相應時間。
報錯信息如下:
org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/javascript, URL=....
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:472)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:167)
at calendarSpider.SpiderTest.testOuGuanMatch(SpiderTest.java:174)
at calendarSpider.SpiderTest.main(SpiderTest.java:39)
在google上查找到了解決方法:添加ignoreContentType(true)
修改後代碼:
private static void testOuGuanMatch() throws IOException{
Document doc = Jsoup.connect("我的URL").ignoreContentType(true).userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)").timeout(5000).get();
System.out.println(doc);
}
那這裏的ignoreContentType(true)看詞就知道忽略ContextType的檢查
---------------------
作者:就算曾經遍體鱗傷也要相信明天
來源:CSDN
原文:https://blog.csdn.net/u010177899/article/details/68061324
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
Jsoup獲取部分頁面數據失敗 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/