Menu

Exception thrown when running LinkExtractor

Help
ctang
2004-07-22
2004-07-22
  • ctang

    ctang - 2004-07-22

    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

     
    • Derrick Oswald

      Derrick Oswald - 2004-07-22

      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
                      }

       

Log in to post a comment.