- 浏览: 943222 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (385)
- 搜索引擎学习 (62)
- 算法 (1)
- 数据库 (15)
- web开发 (38)
- solr开发 (17)
- nutch 1.2 系统学习 (8)
- cms (1)
- 系统架构 (11)
- linux 与 unix 编程 (16)
- android (15)
- maven (1)
- 关注物流 (1)
- 网址收集 (1)
- 分布式,集群 (1)
- mysql (5)
- apache (1)
- 资料文档备份 (7)
- 上班有感 (0)
- 工作流 (15)
- javascript (1)
- weblogic (1)
- eclipse 集成 (1)
- JMS (7)
- Hibernate (1)
- 性能测试 (1)
- spring (6)
- 缓存cache (1)
- mongodb (2)
- webservice (1)
- HTML5 COCOS2D-HTML5 (1)
- BrowserQuest (2)
最新评论
-
avi9111:
内陷到android, ios, winphone里面也是随便 ...
【HTML5游戏开发】二次开发 BrowserQuest 第一集 -
avi9111:
呵呵,做不下去了吧,没有第二集了吧,游戏是个深坑,谨慎进入,其 ...
【HTML5游戏开发】二次开发 BrowserQuest 第一集 -
excaliburace:
方案3亲测完全可用,顺便解决了我其他方面的一些疑问,非常感谢
spring security 2添加用户验证码 -
yuanliangding:
Spring太强大了。
Spring Data JPA 简单介绍 -
小高你好:
什么是hibernate懒加载?什么时候用懒加载?为什么要用懒加载?
键字: heritrix processor
本节解析与处理器有关的内容.
与处理器有关的主要在以下几个类:Processor(处理器类),ProcessorChain(处理器类),ProcessorChainList(处理器链列表).它们之间的关系如下:
下面将解析该图.
(1)Processor
代表一个处理器.
Code
package org.archive.crawler.framework;
public class Processor extends ModuleType {
//默认的下一个处理器
private Processor defaultNextProcessor = null;
/**
* Perform processing on the given CrawlURI.
* 处理一个链接
* @param curi
* @throws InterruptedException
*/
public final void process(CrawlURI curi) throws InterruptedException {
// by default, arrange for curi to proceed to next processor
//设置当前处理器的下一个处理器
curi.setNextProcessor(getDefaultNextProcessor(curi));
// Check if this processor is enabled before processing
try {
if (!((Boolean) getAttribute(ATTR_ENABLED, curi)).booleanValue()) {
return;
}
} catch (AttributeNotFoundException e) {
logger.severe(e.getMessage());
}
if(rulesAccept(curi)) {
innerProcess(curi); //留给子类实现
} else {
innerRejectProcess(curi);
}
}
package org.archive.crawler.framework;
public class Processor extends ModuleType {
//默认的下一个处理器
private Processor defaultNextProcessor = null;
/**
* Perform processing on the given CrawlURI.
* 处理一个链接
* @param curi
* @throws InterruptedException
*/
public final void process(CrawlURI curi) throws InterruptedException {
// by default, arrange for curi to proceed to next processor
//设置当前处理器的下一个处理器
curi.setNextProcessor(getDefaultNextProcessor(curi));
// Check if this processor is enabled before processing
try {
if (!((Boolean) getAttribute(ATTR_ENABLED, curi)).booleanValue()) {
return;
}
} catch (AttributeNotFoundException e) {
logger.severe(e.getMessage());
}
if(rulesAccept(curi)) {
innerProcess(curi); //留给子类实现
} else {
innerRejectProcess(curi);
}
}
Code
(2)ProcessorChain
该类实际上实现一个队列的功能,它代表一个由许多处理器连接的处理器链.
Code
package org.archive.crawler.framework;
public class ProcessorChain {
//存放当前处理链中所有的处理器
private final MapType processorMap;
//下一个处理器链
private ProcessorChain nextChain;
//处理器链的第一个处理器
private Processor firstProcessor;
/** Construct a new processor chain.
* 把该处理链的所有的处理器连接起来
* @param processorMap a map of the processors belonging to this chain.
*/
public ProcessorChain(MapType processorMap) {
this.processorMap = processorMap;
Processor previous = null;
for (Iterator it = processorMap.iterator(null); it.hasNext();) {
Processor p = (Processor) it.next();
if (previous == null) {
firstProcessor = p;
} else {
//设置前一个处理器的下一个处理器为当前处理器
previous.setDefaultNextProcessor(p);
}
logger.info(
"Processor: " + p.getName() + " --> " + p.getClass().getName());
//当前处理器设置为前一个处理器
previous = p;
}
}
/** Set the processor chain that the URI should be working through after
* finishing this one.
* 设置下一个处理器
* @param nextProcessorChain the chain that should be processed after this
* one.
*/
public void setNextChain(ProcessorChain nextProcessorChain) {
this.nextChain = nextProcessorChain;
}
/** Get the processor chain that the URI should be working through after
* finishing this one.
*
* @return the next processor chain.
*/
public ProcessorChain getNextProcessorChain() {
return nextChain;
}
/** Get the first processor in the chain.
* 获取第一个处理器
* @return the first processor in the chain.
*/
public Processor getFirstProcessor() {
return firstProcessor;
}
package org.archive.crawler.framework;
public class ProcessorChain {
//存放当前处理链中所有的处理器
private final MapType processorMap;
//下一个处理器链
private ProcessorChain nextChain;
//处理器链的第一个处理器
private Processor firstProcessor;
/** Construct a new processor chain.
* 把该处理链的所有的处理器连接起来
* @param processorMap a map of the processors belonging to this chain.
*/
public ProcessorChain(MapType processorMap) {
this.processorMap = processorMap;
Processor previous = null;
for (Iterator it = processorMap.iterator(null); it.hasNext();) {
Processor p = (Processor) it.next();
if (previous == null) {
firstProcessor = p;
} else {
//设置前一个处理器的下一个处理器为当前处理器
previous.setDefaultNextProcessor(p);
}
logger.info(
"Processor: " + p.getName() + " --> " + p.getClass().getName());
//当前处理器设置为前一个处理器
previous = p;
}
}
/** Set the processor chain that the URI should be working through after
* finishing this one.
* 设置下一个处理器
* @param nextProcessorChain the chain that should be processed after this
* one.
*/
public void setNextChain(ProcessorChain nextProcessorChain) {
this.nextChain = nextProcessorChain;
}
/** Get the processor chain that the URI should be working through after
* finishing this one.
*
* @return the next processor chain.
*/
public ProcessorChain getNextProcessorChain() {
return nextChain;
}
/** Get the first processor in the chain.
* 获取第一个处理器
* @return the first processor in the chain.
*/
public Processor getFirstProcessor() {
return firstProcessor;
}
Code
(3)ProcessorChainList
该类是保存一次抓取任务的所有的处理器链(ProcessorChain).
Code
package org.archive.crawler.framework;
public class ProcessorChainList {
//处理器链列表,保存所有的处理器链
private List<ProcessorChain> chainList = new ArrayList<ProcessorChain>();
//所有的处理器
private Map<String,ProcessorChain> chainMap
= new HashMap<String,ProcessorChain>();
/** Add a new chain of processors to the chain list.
* 将所有的处理器链添加到Map中
* This method takes a map of processors and wraps it in a ProcessorChain
* object and adds it to the list of chains.
*
* @param processorMap the processor map to be added.
*/
public void addProcessorMap(String name, MapType processorMap) {
//由MapType生成一个处理器链
ProcessorChain processorChain = new ProcessorChain(processorMap);
ProcessorChain previousChain = getLastChain();
if (previousChain != null) {
//设置下一个处理器链
previousChain.setNextChain(processorChain);
}
chainList.add(processorChain);
chainMap.put(name, processorChain);
}
/** Get the first processor chain.
* 获取第一个处理链
* @return the first processor chain.
*/
public ProcessorChain getFirstChain() {
return (ProcessorChain) chainList.get(0);
}
package org.archive.crawler.framework;
public class ProcessorChainList {
//处理器链列表,保存所有的处理器链
private List<ProcessorChain> chainList = new ArrayList<ProcessorChain>();
//所有的处理器
private Map<String,ProcessorChain> chainMap
= new HashMap<String,ProcessorChain>();
/** Add a new chain of processors to the chain list.
* 将所有的处理器链添加到Map中
* This method takes a map of processors and wraps it in a ProcessorChain
* object and adds it to the list of chains.
*
* @param processorMap the processor map to be added.
*/
public void addProcessorMap(String name, MapType processorMap) {
//由MapType生成一个处理器链
ProcessorChain processorChain = new ProcessorChain(processorMap);
ProcessorChain previousChain = getLastChain();
if (previousChain != null) {
//设置下一个处理器链
previousChain.setNextChain(processorChain);
}
chainList.add(processorChain);
chainMap.put(name, processorChain);
}
/** Get the first processor chain.
* 获取第一个处理链
* @return the first processor chain.
*/
public ProcessorChain getFirstChain() {
return (ProcessorChain) chainList.get(0);
}
(4)ToeThread
为了高效抓取网页,Heritrix采用了线程池的设计.每一个线程将调用所有的处理器来处理链接.
Code
private void processCrawlUri() throws InterruptedException {
currentCuri.setThreadNumber(this.serialNumber);
//获取第一个处理器链
currentCuri.setNextProcessorChain(controller.getFirstProcessorChain());
lastStartTime = System.currentTimeMillis();
// System.out.println(currentCuri);
try {
while (currentCuri.nextProcessorChain() != null) {
setStep(STEP_ABOUT_TO_BEGIN_CHAIN);
// Starting on a new processor chain.
//设置下一个处理器
currentCuri.setNextProcessor(currentCuri.nextProcessorChain().getFirstProcessor());
currentCuri.setNextProcessorChain(currentCuri.nextProcessorChain().getNextProcessorChain());
while (currentCuri.nextProcessor() != null) {
setStep(STEP_ABOUT_TO_BEGIN_PROCESSOR);
Processor currentProcessor = getProcessor(currentCuri.nextProcessor());
currentProcessorName = currentProcessor.getName();
continueCheck();
// long memBefore = (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024;
//调用处理器处理链接
currentProcessor.process(currentCuri);
// long memAfter = (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024;
// System.out.println((memAfter-memBefore)+"K in "+currentProcessorName);
}
}
setStep(STEP_DONE_WITH_PROCESSORS);
currentProcessorName = "";
} catch (RuntimeExceptionWrapper e) {
// Workaround to get cause from BDB
if(e.getCause() == null) {
e.initCause(e.getCause());
}
recoverableProblem(e);
} catch (AssertionError ae) {
// This risks leaving crawl in fatally inconsistent state,
// but is often reasonable for per-Processor assertion problems
recoverableProblem(ae);
} catch (RuntimeException e) {
recoverableProblem(e);
} catch (StackOverflowError err) {
recoverableProblem(err);
} catch (Error err) {
// OutOfMemory and any others
seriousError(err);
}
private void processCrawlUri() throws InterruptedException {
currentCuri.setThreadNumber(this.serialNumber);
//获取第一个处理器链
currentCuri.setNextProcessorChain(controller.getFirstProcessorChain());
lastStartTime = System.currentTimeMillis();
// System.out.println(currentCuri);
try {
while (currentCuri.nextProcessorChain() != null) {
setStep(STEP_ABOUT_TO_BEGIN_CHAIN);
// Starting on a new processor chain.
//设置下一个处理器
currentCuri.setNextProcessor(currentCuri.nextProcessorChain().getFirstProcessor());
currentCuri.setNextProcessorChain(currentCuri.nextProcessorChain().getNextProcessorChain());
while (currentCuri.nextProcessor() != null) {
setStep(STEP_ABOUT_TO_BEGIN_PROCESSOR);
Processor currentProcessor = getProcessor(currentCuri.nextProcessor());
currentProcessorName = currentProcessor.getName();
continueCheck();
// long memBefore = (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024;
//调用处理器处理链接
currentProcessor.process(currentCuri);
// long memAfter = (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024;
// System.out.println((memAfter-memBefore)+"K in "+currentProcessorName);
}
}
setStep(STEP_DONE_WITH_PROCESSORS);
currentProcessorName = "";
} catch (RuntimeExceptionWrapper e) {
// Workaround to get cause from BDB
if(e.getCause() == null) {
e.initCause(e.getCause());
}
recoverableProblem(e);
} catch (AssertionError ae) {
// This risks leaving crawl in fatally inconsistent state,
// but is often reasonable for per-Processor assertion problems
recoverableProblem(ae);
} catch (RuntimeException e) {
recoverableProblem(e);
} catch (StackOverflowError err) {
recoverableProblem(err);
} catch (Error err) {
// OutOfMemory and any others
seriousError(err);
}
Code
(5)处理器链的初始化
所有的处理器链都是在CrawlController的initialize中初始化的.
Code
public void initialize(SettingsHandler sH)
{
//初始化了Scope、Frontier以及ProcessorChain
setupCrawlModules();
public void initialize(SettingsHandler sH)
{
//初始化了Scope、Frontier以及ProcessorChain
setupCrawlModules();
CodeCode
Code
Code
private void setupCrawlModules(){
//设置处理链
// Setup processors
if (processorChains == null) {
processorChains = new ProcessorChainList(order);
}
private void setupCrawlModules(){
//设置处理链
// Setup processors
if (processorChains == null) {
processorChains = new ProcessorChainList(order);
}
发表评论
-
nutch1.4 环境变量设置
2012-04-06 12:52 1679Exception in thread "main& ... -
正则使用
2010-06-18 00:19 1098java正则表达式(java.Regex)HtmlParser ... -
nutch 1.0 读源码,过滤掉不正确的URL实现方法
2010-06-18 00:17 3334nutch 1.0 读源码,过滤掉不正确的URL实现方法: ... -
Exception in thread "main" org.apache.hadoop.mapred.InvalidInputExnutch新发现,为以后备忘
2010-06-16 23:16 2261urls -dir mycrawl -depth 3 -top ... -
HTMLParser 解析html字符串,提取纯文本
2010-05-14 09:59 8288今天在群里问别人怎么提取文本,也没有具体告诉我用什么,只是说用 ... -
HTMLParser的两种使用方法[转]
2010-05-13 23:37 1881HTMLParser的两种使用方法 文章分类:Java编程 ... -
搜索引擎术语
2010-05-05 11:40 1390附录. 术语 B: 半结构化 ... -
影响Lucene索引速度原因以及提高索引速度技巧[转]
2010-04-25 00:11 2711影响Lucene索引速度原因以及提高索引速度技巧 关键字: ... -
如何配置compass的索引位置为相对路径
2009-09-01 19:28 1475Compass是对lucene进行封装 ... -
heritrix 基本介绍
2009-08-01 10:35 3845Heritrix使用小结 1. H ... -
我对HtmlParser 提取网页各属性的总结及示例说明
2009-07-08 13:50 1902/** * 属性过滤器 * @param parser ... -
数学之美 系列十三 信息指纹及其应用
2009-06-25 22:34 10052006年8月3日 上午 11:17:00 ... -
数学之美系列二十一 - 布隆过滤器(Bloom Filter)
2009-06-25 22:27 14812007年7月3日 上午 09:35:00 ... -
用HTMLParser提取URL页面超链接的一段代码(小试牛刀)
2009-06-06 16:54 7054用HTMLParser提取URL页面超 ... -
深入学习Heritrix---解析Frontier(链接工厂)
2009-06-06 10:02 1169Frontier是Heritrix最核心的组成部分之一,也是最 ... -
深入学习Heritrix---解析CrawlController
2009-06-06 10:00 1344当我们以Web UI方式使用Heritrix时,点击任务开始( ... -
深入学习Heritrix---解析Frontier(链接工厂)
2009-06-03 21:50 1483原创作者: pengranxiang 阅读:231次 ... -
lucene2.0+heritrix示例补充
2009-06-03 21:31 1505由于lucene2.0+heritrix一书示例用的网站( ... -
htmlparser 使用手册
2009-05-30 16:47 28792009-05-08 14:20 需要做一 ... -
Nutch插件机制和Nutch一个插件实例
2009-05-25 23:54 18232007年06月16日 星期六 15:07 Pl ...
相关推荐
Heritrix 是一个由 java 开发的、开源的网络爬虫,用户可以使用它来从网上抓取想要的资源。官网下载好像要翻墙,我下下来方便大家使用,这是3.4版本,配合heritrix-3.4.0-SNAPSHOT-dist.zip使用
此文件中包括heritrix-1.14.4.zip和heritrix-1.14.4-src.zip 其中src是源码,已测试能够集成到eclipse中进行二次开发
heritrix-1.14.4-src绝对是你想要的那一种,找了很长时间啊,和你一起分享
heritrix-1.14.4-src.zip
heritrix-3.1.0 最新官网jar包。包括heritrix-3.1.0-dist.zip包与heritrix-3.1.0-src.zip包。是爬虫神器
包含: heritrix-3.1.0-dist.tar.gz heritrix-3.1.0-src.tar.gz 官方文档下载地址
heritrix-1.14.2.zip是一个开源项目
heritrix-1.12.1-src.zip与heritrix 配置文档
一个java的网络爬虫程序。heritrix-1.14.0-src
Heritrix-1.14.4源代码,已经建成了项目。直接导入(import)Eclipse中,即可以直接运行。方便广大渴望学习Heritrix源代码的同学。
近期需要使用heritrix-1.14.4,配了半天才配好,这个是控制台执行版本. 注意:解压到相关目录,之后配置系统环境变量"HERITRIX_HOME"到该解压目录(Java环境已经配置好)。 使用控制台命令启动 : heritrix --admin=...
这是我在官方网站下载的,里面还有在myeclipse安装方法及常见问题解决
heritrix-1.14.4爬虫框架及源码
heritrix-1.14.4-src.tar.gz
免费资源,赶紧下载学习。heritrix-1.12.1.zip
heritrix-3.2.0的源码,有意学习爬虫的童鞋,可以研究下源代码!
heritrix是开源的网络爬虫,号称与lucene是黄金搭档!heritrix提供了强大的自定义功能,使用方便灵活!能满足你各种爬行需要!
heritrix-1.4.4 源代码(eclipse可执行) 将源代码解压后导入到eclipse 即可执行
Heritrix 是一个由 java 开发的、开源的网络爬虫,用户可以使用它来从网上抓取想要的资源。官网下载好像要翻墙,我下下来方便大家使用,这是3.4版本
我把下载最新的 heritrix-3.2.0 包 发到网上,供大家下载学习。