1.添加了org.archive.crawler.frontier.ELFHashQueueAssignmentPolicy.java
public class ELFHashQueueAssignmentPolicy extends QueueAssignmentPolicy {
private static final Logger logger = Logger
.getLogger(ELFHashQueueAssignmentPolicy.class.getName());
private static String DEFAULT_CLASS_KEY = "default...";
private static final String DNS = "dns";
/**
*
*/
@Override
public String getClassKey(CrawlController controller, CandidateURI cauri) {
String uri = cauri.getUURI().toString();
String scheme = cauri.getUURI().getScheme();
String candidate = null;
try {
if (scheme.equals(DNS)) {
if (cauri.getVia() != null) {
// Special handling for DNS: treat as being
// of the same class as the triggering URI.
// When a URI includes a port, this ensures
// the DNS lookup goes atop the host:port
// queue that triggered it, rather than
// some other host queue
UURI viaUuri = UURIFactory.getInstance(cauri.flattenVia());
candidate = viaUuri.getAuthorityMinusUserinfo();
// adopt scheme of triggering URI
scheme = viaUuri.getScheme();
} else {
candidate = cauri.getUURI().getReferencedHost();
}
} else {
// String uri = cauri.getUURI().toString();
long hash = ELFHash(uri);
candidate = Long.toString(hash % 100);
}
if (candidate == null || candidate.length() == 0) {
candidate = DEFAULT_CLASS_KEY;
}
} catch (URIException e) {
logger.log(Level.INFO,
"unable to extract class key; using default", e);
candidate = DEFAULT_CLASS_KEY;
}
return candidate.replace(':', '#');
}
public String getClassKey(String uri) {
// String uri = cauri.getUURI().toString();
long hash = ELFHash(uri);
String a = Long.toString(hash % 100);
return a;
}
public static long ELFHash(String str) {
long hash = 0;
long x = 0;
for (int i = 0; i < str.length(); i++) {
hash = (hash << 4) + str.charAt(i);
if ((x = hash & 0xF0000000L) != 0) {
hash ^= (x >> 24);
hash &= ~x;
}
}
return (hash & 0x7FFFFFFF);
}
public static void main(String args[]){
ELFHashQueueAssignmentPolicy el=new ELFHashQueueAssignmentPolicy();
String a=el.getClassKey("http://www.chinanews.com.cn/");
System.out.println(a);
}
}
2.修改了AbstractFrontier 类的AbstractFrontier方法
/**
* 自己添加修改的配置----------------------------
*/
String queueStr = System.getProperty(AbstractFrontier.class.getName() +
"." + ATTR_QUEUE_ASSIGNMENT_POLICY,
ELFHashQueueAssignmentPolicy.class.getName() + " " +
IPQueueAssignmentPolicy.class.getName() + " " +
BucketQueueAssignmentPolicy.class.getName() + " " +
SurtAuthorityQueueAssignmentPolicy.class.getName() + " " +
TopmostAssignedSurtQueueAssignmentPolicy.class.getName());
Pattern p = Pattern.compile("\\s*,\\s*|\\s+");
/**
* -----------------------------------------------
*/
3.修改了heritrix.properties
修改为
#############################################################################
# FRONTIER
#############################################################################
# List here all queue assignment policies you'd have show as a
# queue-assignment-policy choice in AbstractFrontier derived Frontiers
# (e.g. BdbFrontier).
org.archive.crawler.frontier.AbstractFrontier.queue-assignment-policy = org.archive.crawler.frontier.ELFHashQueueAssignmentPolicy org.archive.crawler.frontier.IPQueueAssignmentPolicy org.archive.crawler.frontier.BucketQueueAssignmentPolicy org.archive.crawler.frontier.SurtAuthorityQueueAssignmentPolicy org.archive.crawler.frontier.TopmostAssignedSurtQueueAssignmentPolicy
org.archive.crawler.frontier.BdbFrontier.level = INFO
要新建一个job才有效,否则还是默认的HostnameQueueAssignmentPolicy
还有,有时候只是散列出30个DNS就关闭。
解决方法1,增加入口连接
2,对这个job重新建立以下with exist
分享到:
相关推荐
C#多线程抓取数据(艺龙酒店) 各种类以及封装好了
由于线程起始时启动的方法不能带有参数,这就为多线程共享资源添加了麻烦。不过我们可以用类级变量(当然也可以使用其它方法,笔者认为此方法最简单易用)来解决这个问题。知道开启多线程下载的方法后,大家可能会...
自己写的一个多线程爬虫,在当前目录下创建目录保存相应图片,共100行代码,可以正常运行
描述:由C#编写的多线程异步抓取网页的网络爬虫控制台程序 功能:目前只能提取网络链接,所用的两个记录文件并不需要很大。网页文本、图片、视频和html代码暂时不能抓取,请见谅。 但需要注意,网页的数目是非常...
java爬虫多线程抓取图片,压缩包里边里边含有三个例子,博主亲测使用,没有问题,欢迎大家在博客给我留言,一起交流技术问题。
java 多线程抓取去哪儿qunar机票数据,依赖 httpclient ,jsoud 等jar 包
多线程抓取网页数据 抓取七星彩开奖号码 程抓取网页数据
curl 多线程抓取 */ /** * curl 多线程 * * @param array $array 并行网址 * @param int $timeout 超时时间 * @return array */ function Curl_http($array,$timeout){ $res = array(); $mh = curl_multi_...
PHP多线程抓取多个网页及获取数据的通用方法.pdf
多线程网页信息抓取实现,强大的信息抓取功能
想实现用c++下载网页,这是个很好的例子
学习用的,python写的多线程抓取代理服务器,保存,验证程序-烤火C知识网
这是一个多线程抓取知乎用户的程序 Requirements 需要用到的包: beautifulsoup4 html5lib image requests redis PyMySQL pip安装所有依赖包: pip install Image requests beautifulsoup4 ...
c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程c_多线程...
这是一个多线程用jsoup抓取网站新闻内容的demo,详细的代码示例,使用这个工具类主要知道如何从抓取的html文档里根据标签取内容就OK了。简单粗暴。
C#编写的spider demo 主要实现多线程的网页抓取及网页内容中URL的提取
人工智能-项目实践-多线程-多线程爬虫--抓取淘宝商品详情页URL 本项目是一个Java编写的多线程爬虫系统。此系统与我之前开发的ip-proxy-pools-regularly结合使用,共抓取了淘宝近3000个页面,从中解析到了近9万的...
适合:简单地获取纯文字网页的内容。需要创建子线程or修改爬取网页请在testpc.java中修改,webpc用于获取指定网页内容,runthread用于创建子线程爬虫,testpc则是主线程,用于管理子线程的创建、运行与等待。
多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程多线程
一个Python多线程爬虫,在工作时,开10个线程来抓取新浪网页的数据,抓取并保存页面, 并且根据deep返回页面链接,根据key确定是否保存该页面,其中: deep == 0时,是抓取的最后一层深度,即只抓取并保存页面,不...