gpt4 book ai didi

java - HTMLUnit - 如何获取传出连接列表作为列表?

转载 作者:行者123 更新时间:2023-11-30 04:13:51 25 4
gpt4 key购买 nike

我正在尝试获取与 HTMLunit 的连接列表。到目前为止,我已经将它与调试器(DebuggingWebConnection)一起使用了。但是我只希望该函数将连接作为列表返回。调试器也会下载所有内容。

public static void crawlPage() throws Exception {
final WebClient wc = new WebClient();
String resultFolder = "results";
final WebConnection connection = new DebuggingWebConnection(wc.getWebConnection(), resultFolder);
wc.setWebConnection(connection);
HtmlPage page = (HtmlPage) wc.getPage("http://www.test.com");

}

在results/index.html中返回;

GET http://www.test.com/ 200 (text/html) 14.53 Kib, 866ms
GET http://www.google-analytics.com/ga.js 200 (text/javascript) 77.38 Kib, 399ms
GET http://www.google-analytics.com/__utm.gif?utmwv=5.4.5&utms=1&utmn=1203166335&utmhn=www.test.com&utmcs=utf-8&utmsr=1024x768&utmvp=1256x605&utmsc=24-bit&utmul=en-us&utmje=0&utmfl=-&utmdt=Create%20Tests%20for%20Organizational%20Training%20and%20Certification%20Programs%20%E2%80%93%20Test.com&utmhid=121499150&utmr=-&utmp=%2F&utmht=1379757739907&utmac=UA-3518049-1&utmcc=__utma%3D99889051.1275286197.1379757740.1379757740.1379757740.1%3B%2B__utmz%3D99889051.1379757740.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&utmu=q~ 200 (image/gif) 0.03 Kib, 23ms
GET http://www.test.com/content/js/jquery.min.js 200 (application/x-javascript) 166.71 Kib, 981ms
GET http://www.test.com/content/style.css 200 (text/css) 15.44 Kib, 323ms
GET http://www.test.com/content/flexslider.css 200 (text/css) 2.68 Kib, 395ms
GET http://www.test.com/content/jquery.fancybox-1.3.4.css 200 (text/css) 8.76 Kib, 313ms
GET http://www.test.com/content/jwplayer/jwplayer.js 200 (application/x-javascript) 326.94 Kib, 724ms
GET http://www.test.com/content/js/jquery.flexslider-min.js 200 (application/x-javascript) 21.44 Kib, 320ms
GET http://www.test.com/content/js/jquery.fancybox-1.3.4.js 200 (application/x-javascript) 33.31 Kib, 364ms
GET http://www.test.com/content/js/functions.js 200 (application/x-javascript) 1.87 Kib, 223ms
GET http://www.test.com/assets/_video_thumbnail/47-9a8803a2.png 200 (image/png) 223.8 Kib, 692ms
GET http://l.longtailvideo.com/download/5/9/logo.png 200 (image/png) 1.8 Kib, 26ms
GET http://www.test.com/assets/_video_thumbnail/92-7b078568.png 200 (image/png) 213.78 Kib, 1421ms
GET http://www.test.com/assets/_video_thumbnail/90-d8d9524d.png 200 (image/png) 229.09 Kib, 595ms
GET http://www.test.com/assets/_video_thumbnail/93-52d92cf8.png 200 (image/png) 221.17 Kib, 587ms

有人知道如何在不使用调试器的情况下获取此列表吗?

最佳答案

我认为您不会找到一种简单的方法来做到这一点。主要是因为 HtmlUnit 是一个 headless 浏览器,而不是一个对连接进行操作的低级库(如 HtmlUnit 使用的 Apache HttpClient 类)。

也许,您应该重新考虑 HtmlUnit 的使用。如果您仍然想使用 HtmlUnit,那么我想您必须查看 DebuggingWebConection 的代码才能将其用作指导并创建您自己的 WebConnection 实现,这可能会继承自WebConnectionWrapper。然后您必须自己处理连接列表的创建和维护。

关于java - HTMLUnit - 如何获取传出连接列表作为列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18931350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com