[转]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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值