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

目录
相关文章
|
4月前
|
JSON Java 数据格式
有关Java调用第三方接口【Content-type为form-data】的示例代码
有关Java调用第三方接口【Content-type为form-data】的示例代码
164 0
|
XML JSON 人工智能
Error while extracting response for type [class xxx] and content type application/xml;charset=UTF-8
Error while extracting response for type [class xxx] and content type application/xml;charset=UTF-8
874 0
|
2月前
|
XML 数据格式 Python
【Python】已解决:xml.parsers.expat.ExpatError: no element found: Line 1, column 0
【Python】已解决:xml.parsers.expat.ExpatError: no element found: Line 1, column 0
51 0
|
10月前
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]
240 0
|
4月前
|
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...]
392 0
|
Java 测试技术
body-parser:unsupported content encoding 错误
最近遇到了一个奇怪的问题,关于body-parser报错,我本地调用没问题,使用测试工具没问题,这种方案都没问题,就和我对接的程序调用有问题,于是开始了面向百度编程,查到了两种解决方案:
498 0
body-parser:unsupported content encoding 错误
|
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的解决
2751 0
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
|
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-
|
存储 数据库 数据可视化