java.nio.charset.IllegalCharsetNameException:'ISO-8859-1' [英] java.nio.charset.IllegalCharsetNameException: 'ISO-8859-1'
问题描述
Jsoup.connect("http://www.design.cmu.edu/community.php?s=3").get();
有人可以告诉我为什么代码给我错误:
Could someone please show me why the code gave me the error:
java.nio.charset.IllegalCharsetNameException: 'ISO-8859-1'
推荐答案
问题出现在目标页面。
The problem is in the target page. It is not well-formed at all.
当解析页面时,JSoup尝试修复页面,一件事是将内容类型解析为text / html; charset ='iso-8859-1'(带单引号)。
When parsing the page, JSoup tries to fix the page and for one thing, parses the content type to "text/html; charset='iso-8859-1'"(with the single quotes included).
然后传递此字符串(使用单引号),并使用它charset:
It then passes this string(with the single quotes) and uses it to get the charset:
Charset.forName("'ISO-8859-1'");
这会失败。
在目标页面。
也许你可以使用这个替代方法,它不解析页面中的字符集,因为你明确地传递它:
The problem is in the target page. Maybe you can use this alternative instead, which doesn't parse the charset from the page, because you explicitly pass it along:
String url = "http://www.design.cmu.edu/community.php?s=3";
Document document = Jsoup.parse(new URL(url).openStream(), "ISO-8859-1", url);
这篇关于java.nio.charset.IllegalCharsetNameException:'ISO-8859-1'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!