用httpunit写的spider程序:可以监测网站的错误页面!
来源:互联网 发布:cf占卜活动软件 编辑:程序博客网 时间:2024/06/05 17:26
这个程序出自Java Tools for Extreme Programming一书。
import com.meterware.httpunit.*;
import java.util.HashSet;
import java.util.Set;
public class CheckSite {
private WebConversation conversation;
private Set checkedLinks;
private String host = "www.sohu.com";
public static void main(String[] args) throws Exception {
CheckSite cs = new CheckSite();
cs.setUp();
cs.testEntireSite();
}
public void setUp() {
conversation = new WebConversation();
checkedLinks = new HashSet();
}
public void testEntireSite() throws Exception {
WebResponse response = conversation.getResponse("http://" + host);
checkAllLinks(response);
System.out.println("Site check finished. Link's checked: "
+ checkedLinks.size() + " : " + checkedLinks);
}
private void checkAllLinks(WebResponse response) throws Exception {
if (!isHtml(response)) {
return;
}
WebLink[] links = response.getLinks();
System.out.println(response.getTitle() + " -- links found = "
+ links.length);
for (int i = 0; i < links.length; i++) {
boolean newLink = checkedLinks.add(links[i].getURLString());
if (newLink) {
System.out.println("Total links checked so far: "
+ checkedLinks.size());
checkLink(links[i]);
}
}
}
private boolean isHtml(WebResponse response) {
return response.getContentType().equals("text/html");
}
private void checkLink(WebLink link) throws Exception {
WebRequest request = link.getRequest();
java.net.URL url = request.getURL();
System.out.println("checking link: " + url);
String linkHost = url.getHost();
if (linkHost.equals(this.host)) {
WebResponse response = conversation.getResponse(request);
this.checkAllLinks(response);
}
}
}
- 用httpunit写的spider程序:可以监测网站的错误页面!
- 用HttpUnit写servlet的单元测试
- 今天整理硬盘居然发现了以前写的网站服务器监测程序,可以监测服务器当机否,并可EMAIL通知
- spider简单的爬虫程序
- spider简单的爬虫程序
- sougou spider,iask spider先后来肆虐我的网站
- 网站监测的新动向
- IIS6.0 ,网站上的html可以正常访问,asp页面提示找不到页面404 错误
- python写的一个简单的spider
- 关闭HttpUnit不支持的JavaScript语句,并查看错误
- 关于写一个spider的计划
- 写Spider中遇到的问题
- 写程序的低级错误
- 网络爬虫(spider)程序的编程实现
- 网络爬虫(spider)程序的编程实现
- 网络爬虫(spider)程序的编程实现
- 网络爬虫(spider)程序的编程实现
- 网络爬虫(spider)程序的编程实现
- 点对点语音通信
- Preparing Your Visual Basic 6.0 Applications for the Upgrade to Visual Basic .NET
- 使用FDO封装XML&ADO实现与服务端数据通信
- 对于模式的“十大误解”
- Remote Debug with Java Application Server
- 用httpunit写的spider程序:可以监测网站的错误页面!
- JBuilder9+Weblogic8.1+mysql配置手记
- 心如刀割:女友元旦结婚,新郎不是我! (转载)
- Java面试题目(1)
- 防止sql注入的简单方法
- Delphi编写soap服务器与客户端程序
- 在blog中显示天气预报、日历、时钟、MSN、QQ在线状态、中国农历
- 有时候,汇编比高级语言更易懂
- DOOM启世录——感