Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用HTTPUNIT获取网页上的链接数?_Java_Html Parsing_Http Unit - Fatal编程技术网

Java 无法使用HTTPUNIT获取网页上的链接数?

Java 无法使用HTTPUNIT获取网页上的链接数?,java,html-parsing,http-unit,Java,Html Parsing,Http Unit,我已经开始学习HTTPUNIT,并找到了一个基本示例 在本例中,它将访问此。 它将搜索包含的链接。它会在网页上打印链接的数量。我在我的机器上试过这个例子,它是有效的 WebConversation wc = new WebConversation(); WebRequest request = new GetMethodWebRequest( "http://www.meterware.com" ); WebResponse response =

我已经开始学习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)
为什么它不能访问谷歌新闻并获得链接的数量


提前谢谢。

谷歌主页是用JavaScript呈现的


HTTPUNIT已经完成。如果您需要使用繁重的JavaScript测试页面,请查看更具体的“WebDriver”,它是Selenium的一部分。@Devon它有点像QTP吗?“快速测试专家“@vikii在概念上相似。Selenium Webdriver与浏览器挂钩,让您控制它与网站的交互。@Devon您能给我举个例子,让我看看这个例子吗?我从来没有听说过Selenium Webdriver。所以不知道从哪里开始。@vikiii我要到本周晚些时候才会有时间,但我会用一个例子来更新它。同时,拥有一个通读http//seleniumhq.org/docs