If LinkExtractor runs againest a english site, everything works fine.
If LinkExtractor runs againest a chinese site such as www.zaobao.com, which has <META http-equiv=Content-Type content="text/html; charset=gb2312">, an exception is thrown,
org.htmlparser.util.EncodingChangeException: character mismatch (new: ? != old: ) for encoding change from ISO-8859-1 to x-EUC-CN at character offset 113
at org.htmlparser.lexer.Page.setEncoding(Page.java:743)
at org.htmlparser.tags.MetaTag.doSemanticAction(MetaTag.java:117)
at org.htmlparser.scanners.TagScanner.scan(TagScanner.java:69)
at org.htmlparser.scanners.CompositeTagScanner.scan(CompositeTagScanner.java:162)
at org.htmlparser.util.IteratorImpl.nextNode(IteratorImpl.java:92)
at org.htmlparser.Parser.extractAllNodesThatMatch(Parser.java:774)
at org.htmlparser.parserapplications.LinkExtractor.main(LinkExtractor.java:84)
How to overcome this? I am using 1.5 version of htmlparser.
Thanks!
ctang
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Try again with the parser now having the correct characterset:
catch (EncodingChangeException ece)
{
try
{ // try again with the encoding now in force
mParser.reset ();
mParser.visitAllNodesWith (this);
}
catch (ParserException pe)
{
// uh oh
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
If LinkExtractor runs againest a english site, everything works fine.
If LinkExtractor runs againest a chinese site such as www.zaobao.com, which has <META http-equiv=Content-Type content="text/html; charset=gb2312">, an exception is thrown,
org.htmlparser.util.EncodingChangeException: character mismatch (new: ? != old: ) for encoding change from ISO-8859-1 to x-EUC-CN at character offset 113
at org.htmlparser.lexer.Page.setEncoding(Page.java:743)
at org.htmlparser.tags.MetaTag.doSemanticAction(MetaTag.java:117)
at org.htmlparser.scanners.TagScanner.scan(TagScanner.java:69)
at org.htmlparser.scanners.CompositeTagScanner.scan(CompositeTagScanner.java:162)
at org.htmlparser.util.IteratorImpl.nextNode(IteratorImpl.java:92)
at org.htmlparser.Parser.extractAllNodesThatMatch(Parser.java:774)
at org.htmlparser.parserapplications.LinkExtractor.main(LinkExtractor.java:84)
How to overcome this? I am using 1.5 version of htmlparser.
Thanks!
ctang
Try again with the parser now having the correct characterset:
catch (EncodingChangeException ece)
{
try
{ // try again with the encoding now in force
mParser.reset ();
mParser.visitAllNodesWith (this);
}
catch (ParserException pe)
{
// uh oh
}