我已经开始学习 HTTPUNIT 并找到了一个基本示例。
在本例中,它将访问该站点。它将搜索包含HTTPUNIT的链接。它将打印HTTPUNIT上的链接数。我在我的机器上尝试了这个例子,它可以工作。
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest( "http://www.meterware.com" );
WebResponse response = wc.getResponse( request );
WebLink httpunitLink = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "HttpUnit" );
response = httpunitLink.click();
System.out.println( "The HttpUnit main page contains " + response.getLinks().length + " links" );
现在我已将代码更改为
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest( "http://www.google.com" );
WebResponse response = wc.getResponse( request );
WebLink httpunitLink = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "News" );
response = httpunitLink.click();
System.out.println( "The HttpUnit main page contains " + response.getLinks().length + " links" );
现在它给出了下面的错误。
ConversionError: The undefined value has no properties. (httpunit; line 4)
为什么无法访问谷歌新闻并获取链接数?
先感谢您。