org.htmlparser.util.ParserException: Error in opening a connection to

使用HTMLparser时碰到一个错误

org.htmlparser.util.ParserException: Error in opening a connection to

java.io.IOException: Invalid argument

 at java.io.WinNTFileSystem.canonicalize0(Native Method)

 at java.io.Win32FileSystem.canonicalize(Win32FileSystem.java:396)

 at java.io.File.getCanonicalPath(File.java:559)

 at org.htmlparser.http.ConnectionManager.openConnection(ConnectionManager.java:774)

 at org.htmlparser.Parser.<init>(Parser.java:304)

 at org.htmlparser.Parser.<init>(Parser.java:316)

 at tentsoft.util.CNLinkInfParser.doCNLinkInfParser(CNLinkInfParser.java:62)

 at tentsoft.util.CNLinkInfParser.getCNLinkList(CNLinkInfParser.java:111)

 at tentsoft.util.CNLinkInfParser.main(CNLinkInfParser.java:138)


仔细查看源代码,发现是在
myParser = new Parser(htmlBody);这句出错

其中htmlBody是我request到一个网站得到的response,类型为String.
但是报错。
最后通过定义一个方法

     /**
     * 解析字符串
     * @param inputHTML String
     * @return Parser
     */
    public static Parser createParser(String inputHTML) {
        Lexer mLexer = new Lexer(new Page(inputHTML));
        return new Parser(mLexer,
                          new DefaultParserFeedback(DefaultParserFeedback.QUIET));
    }

在createParser里面去做new Parser()的。
问题解决。而上面的myParser = new Parser(htmlBody)语句改成myParser = createParser(htmlBody)就行了

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/rudyMatrix/archive/2007/11/18/1891663.aspx

原文地址:https://www.cnblogs.com/loveyakamoz/p/2136668.html