Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, appl

简介: Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, appl

Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/

错误代码:

org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/json;charset=UTF-8, URL=http://search.gmw.cn/service/search.do?q=%E4%B8%80%E5%B8%A6%E4%B8%80%E8%B7%AF&c=n&cp=1

googl找到个方法

 

Connection connection = Jsoup.connect(url);
            Map<String, String> header = new HashMap<String, String>();
            header.put(
                    "Accept",
                    "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
            header.put("Accept-Encoding", "gzip, deflate");
            header.put("Accept-Language", "zh-CN,zh;q=0.9");
            header.put("Cache-Control", "max-age=0");
            header.put("Connection", "close");
            header.put(
                    "User-Agent",
                    "Mozilla/5.0 (Windows NT 10.0; Win64; x64;X11; Linux 64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36");
            doc = connection.ignoreContentType(true).headers(header)
                    .timeout(30000).get();

加了个    .ignoreContentType(true)    

忽略ContentType检查

目录
相关文章
|
7月前
|
JSON Java 数据格式
有关Java调用第三方接口【Content-type为form-data】的示例代码
有关Java调用第三方接口【Content-type为form-data】的示例代码
289 0
|
3月前
|
JSON Java 数据格式
java调用服务报错415 Content type ‘application/octet-stream‘ not supported
java调用服务报错415 Content type ‘application/octet-stream‘ not supported
91 1
poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
354 0
|
7月前
|
JSON Java 数据格式
Could not extract response: no suitable HttpMessageConverter found for ..content type [text/html...]
Could not extract response: no suitable HttpMessageConverter found for ..content type [text/html...]
727 0
|
XML 数据安全/隐私保护 数据格式
Minio出现Non-XML response from server. Response code: 400, Content-Type: text/xml; ch的解决
Minio出现Non-XML response from server. Response code: 400, Content-Type: text/xml; ch的解决
3565 0
|
XML Java 数据格式
xml文件报错Element ‘beans‘ cannot have character [children), because the type‘s content type is element-
xml文件报错Element ‘beans‘ cannot have character [children), because the type‘s content type is element-
xml文件报错Element ‘beans‘ cannot have character [children), because the type‘s content type is element-
|
Java Android开发
Unable to load class ‘javax.xml.bind.annotation.XmlSchema‘.
Unable to load class ‘javax.xml.bind.annotation.XmlSchema‘.
895 0
Unable to load class ‘javax.xml.bind.annotation.XmlSchema‘.
|
JavaScript Java
Java Web——jQuery中的过滤器与第一组函数(val、text、attr)
Java Web——jQuery中的过滤器与第一组函数(val、text、attr)
Java Web——jQuery中的过滤器与第一组函数(val、text、attr)
|
JSON 前端开发 Java
【Json与Ajax交互报错解决】No converter found for return value of type: class com.github.pagehelper.PageInfo
【Json与Ajax交互报错解决】No converter found for return value of type: class com.github.pagehelper.PageInfo
331 0
【Json与Ajax交互报错解决】No converter found for return value of type: class com.github.pagehelper.PageInfo
|
XML Java 数据格式
Myeclipse中java web.xml报错cvc-complex-type.2.3: Element 'web-app' cannot have character [children], because the type's content type is element- only.
web.xml文件添加servlet访问限制后出现如下错误:   cvc-complex-type.2.3: Element 'web-app' cannot have character [children], because the type's content type is element- only. 翻译:   cvc-complex-type.2.3:元素'web-app'不能包含character [children],因为该类型的内容类型是仅包含元素的。
3892 0