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检查

目录
相关文章
|
6月前
|
JSON Java 数据格式
有关Java调用第三方接口【Content-type为form-data】的示例代码
有关Java调用第三方接口【Content-type为form-data】的示例代码
269 0
|
2月前
|
JSON Java 数据格式
java调用服务报错415 Content type ‘application/octet-stream‘ not supported
java调用服务报错415 Content type ‘application/octet-stream‘ not supported
83 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]
322 0
|
6月前
|
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...]
651 0
|
12月前
|
JSON C++ 数据格式
VS Code中将 “ .art “ 文件识别为 “ .html “ 文件
VS Code中将 “ .art “ 文件识别为 “ .html “ 文件
73 0
|
Java 测试技术
body-parser:unsupported content encoding 错误
最近遇到了一个奇怪的问题,关于body-parser报错,我本地调用没问题,使用测试工具没问题,这种方案都没问题,就和我对接的程序调用有问题,于是开始了面向百度编程,查到了两种解决方案:
535 0
body-parser:unsupported content encoding 错误
|
存储 应用服务中间件
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
|
JSON 前端开发 数据格式
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `object` out of START_ARRAY token
讲述如何处理 org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `object` out of START_ARRAY token的问题
 org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `object` out of START_ARRAY token
|
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
325 0
【Json与Ajax交互报错解决】No converter found for return value of type: class com.github.pagehelper.PageInfo