当前位置: 代码迷 >> HTML/CSS >> [转]org.htmlparser.util.ParserException: Error in opening a connection to *
  详细解决方案

[转]org.htmlparser.util.ParserException: Error in opening a connection to *

热度:853   发布时间:2012-09-23 10:28:11.0
[转]org.htmlparser.util.ParserException: Error in opening a connection to ***

?

星期六 2007年09月01日

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)就行了

下面是HTMLparser相关的资料:
http://www.hexiao.cn/blog/p/aboutHtmlParser.php
http://www.hexiao.cn/blog/p/use_htmlparser_get_urls.php
http://www.cnblogs.com/doll-net/archive/2007/06/29/800396.html
http://blog.csdn.net/yjboy1982/archive/2007/07/16/1693687.aspx
http://blog.csdn.net/jinxi/archive/2007/01/18/1487017.aspx
http://blog.csdn.net/eqxu/archive/2007/05/29/1629820.aspx

?

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/rudyMatrix/article/details/1891663

?

  相关解决方案