【Heritrix基础教程之4】开始一个爬虫抓取的全流程代码分析
在创建一个job后,就要开始job的运行,运行的全流程如下:
1、在界面上启动job
2、index.jsp
查看上述页面对应的源代码
<a href='"+request.getContextPath()+"/console/action.jsp?action=start'>Start</a>
3、action.jsp
String sAction = request.getParameter("action");
if(sAction != null)
{
// Need to handle an action
if(sAction.equalsIgnoreCase("start"))
{
// Tell handler to start crawl job
handler.startCrawler();
} else if(sAction.equalsIgnoreCase("stop")) {
// Tell handler to stop crawl job
handler.stopCrawler();
} else if(sAction.equalsIgnoreCase("terminate")) {
// Delete current job
if(handler.getCurrentJob()!=null){
handler.deleteJob(handler.getCurrentJob().getUID());
}
} else if(sAction.equalsIgnoreCase("pause")) {
// Tell handler to pause crawl job
handler.pauseJob();
} else if(sAction.equalsIgnoreCase("resume")) {
// Tell handler to resume crawl job
handler.resumeJob();
} else if(sAction.equalsIgnoreCase("checkpoint")) {
if(handler.getCurrentJob() != null) {
handler.checkpointJob();
}
}
}
response.sendRedirect(request.getContextPath() + "/index.jsp");
4、CrawlJobHandler.jsp
(1)
public void startCrawler() {
running = true;
if (pendingCrawlJobs.size() > 0 && isCrawling() == false) {
// Ok, can just start the next job
startNextJob();
}
}
(2)
protected final void startNextJob() {
synchronized (this) {
if(startingNextJob != null) {
try {
startingNextJob.join();
} catch (InterruptedException e) {
e.printStackTrace();
return;
}
}
startingNextJob = new Thread(new Runnable() {
public void run() {
startNextJobInternal();
}
}, "StartNextJob");
startingNextJob.start();
}
}
(3)
protected void startNextJobInternal() {
if (pendingCrawlJobs.size() == 0 || isCrawling()) {
// No job ready or already crawling.
return;
}
this.currentJob = (CrawlJob)pendingCrawlJobs.first();
assert pendingCrawlJobs.contains(currentJob) :
"pendingCrawlJobs is in an illegal state";
pendingCrawlJobs.remove(currentJob);
try {
this.currentJob.setupForCrawlStart();
// This is ugly but needed so I can clear the currentJob
// reference in the crawlEnding and update the list of completed
// jobs. Also, crawlEnded can startup next job.
this.currentJob.getController().addCrawlStatusListener(this);
// now, actually start
this.currentJob.getController().requestCrawlStart();
} catch (InitializationException e) {
loadJob(getStateJobFile(this.currentJob.getDirectory()));
this.currentJob = null;
startNextJobInternal(); // Load the next job if there is one.
}
}
(4)
public void requestCrawlStart() {
runProcessorInitialTasks(); sendCrawlStateChangeEvent(STARTED, CrawlJob.STATUS_PENDING);
String jobState;
state = RUNNING;
jobState = CrawlJob.STATUS_RUNNING;
sendCrawlStateChangeEvent(this.state, jobState); // A proper exit will change this value.
this.sExit = CrawlJob.STATUS_FINISHED_ABNORMAL; Thread statLogger = new Thread(statistics);
statLogger.setName("StatLogger");
statLogger.start(); frontier.start();
}
【Heritrix基础教程之4】开始一个爬虫抓取的全流程代码分析的更多相关文章
- 【Heritrix基础教程之1】在Eclipse中配置Heritrix
一.新建项目并将Heritrix源代码导入 1.下载heritrix-1.14.4-src.zip和heritrix-1.14.4.zip两个压缩包,并解压,以后分别简称SRC包和ZIP包: 2.在E ...
- 【Heritrix基础教程之1】在Eclipse中配置Heritrix 分类: H3_NUTCH 2014-06-01 00:00 1262人阅读 评论(0) 收藏
一.新建项目并将Heritrix源码导入 1.下载heritrix-1.14.4-src.zip和heritrix-1.14.4.zip两个压缩包,并解压,以后分别简称SRC包和ZIP包: 2.在Ec ...
- 【Heritrix基础教程之3】Heritrix的基本架构
Heritrix可分为四大模块: 1.控制器CrawlController 2.待处理的uri列表 Frontier 3.线程池 ToeThread 4.各个步骤的处理器 (1)Pre-fetch ...
- 【Heritrix基础教程之3】Heritrix的基本架构 分类: H3_NUTCH 2014-06-01 16:56 1267人阅读 评论(0) 收藏
Heritrix可分为四大模块: 1.控制器CrawlController 2.待处理的uri列表 Frontier 3.线程池 ToeThread 4.各个步骤的处理器 (1)Pre-fetch ...
- 【Heritrix基础教程之2】Heritrix基本内容介绍
1.版本说明 (1)最新版本:3.3.0 (2)最新release版本:3.2.0 (3)重要历史版本:1.14.4 3.1.0及之前的版本:http://sourceforge.net/projec ...
- 【Heritrix基础教程之2】Heritrix基本内容介绍 分类: B1_JAVA H3_NUTCH 2014-06-01 13:02 878人阅读 评论(0) 收藏
1.版本说明 (1)最新版本:3.3.0 (2)最新release版本:3.2.0 (3)重要历史版本:1.14.4 3.1.0及之前的版本:http://sourceforge.net/projec ...
- OpenVAS漏洞扫描基础教程之OpenVAS概述及安装及配置OpenVAS服务
OpenVAS漏洞扫描基础教程之OpenVAS概述及安装及配置OpenVAS服务 1. OpenVAS基础知识 OpenVAS(Open Vulnerability Assessment Sys ...
- Python基础教程之List对象 转
Python基础教程之List对象 时间:2014-01-19 来源:服务器之家 投稿:root 1.PyListObject对象typedef struct { PyObjec ...
- Python基础教程之udp和tcp协议介绍
Python基础教程之udp和tcp协议介绍 UDP介绍 UDP --- 用户数据报协议,是一个无连接的简单的面向数据报的运输层协议.UDP不提供可靠性,它只是把应用程序传给IP层的数据报发送出去,但 ...
随机推荐
- (原)ubuntu上安装Torch7及nn及dpnn
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5653864.html 参考网址: http://torch.ch/docs/getting-start ...
- JavaScript this 局部变量全局变量 作用域 作用域链 闭包
从阮老师博客的一道测试题说起: 代码段一: var name = "The Window"; var object = { name : "My Object" ...
- jquery向列表添加新元素
$(function () { $('#btn').click(function () { $('ol').append('<li>'+$('#text').val()+'</li& ...
- QT字体的设置
摘要: QT4.7.0在移植到开发板上的时候,中文支持是必不可少的,如何让QT支持中文,如何制作QT支持的字体文件,如何使QT UI编辑器中的字号与开发板中的字号一致.作者通过实验进行了一一验证. 介 ...
- JSON数据解析——jsoncpp的使用
版权所有,转载请注明:http://blog.sina.com.cn/u/1978765352 由于工作中需要用到JSON数据,所以解析JSON数据就成了一个非常重要的工作内容. 其实用C++解析数据 ...
- iphone6闪存检测
iPhone6自从发布以后一直又不少的诟病和非议,比如一机难求,容易掰弯,程序崩溃等, 甚至传出了苹果将要召回这些问题设备,最近有人终于查出了iPhone6安装大量程序后崩溃的原因,原因就是大容量的i ...
- Safari HTML5 Canvas Guide: Creating Charts and Graphs
Safari HTML5 Canvas Guide: Creating Charts and Graphs Bar graphs are similar to data plots, but each ...
- Extjs实现进度条
做Extjs开发中,往往后台程序可能要执行一段时间才能得到返回结果,加入进度条可以提高客户体验度,以下为两种便捷的方式: 1.提交数据前用Ext.Msg.wait('提示','正在处理数据,请稍候') ...
- 【错误】:MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
错误:MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 解决 ...
- category和extensions
catgory 允许你为一个已经存在的类增加方法,而不需要增加一个子类.而且不需要知道它内部具体的实现. 另外,虽然Category不能够为类添加新的成员变量,但是Category包含类的所有成员变量 ...