zoukankan      html  css  js  c++  java
  • Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/

    用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.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
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    asp.net core abp 视频教程1
    一种简单、易用的顶尖学习法——费曼学习法
    WPF附加属性
    WPF popup被截断的原因和修改方法
    cefsharp 在anycpu下运行
    XP系统运行wpf程序出现透明现象的解决
    Visual studio 2017 Installer 打包.netframework
    WPF Datagrid横向排列
    “App.exe 以附加有调试器,但没有将该调试器配置为调试此未经处理的异常。”
    Head First Python学习笔记4——处理数据
  • 原文地址:https://www.cnblogs.com/GH0522/p/9837604.html
Copyright © 2011-2022 走看看