前阵子找工作的时候经常会看到epoll多路复用的知识点,无奈自己一点都不懂。慌忙之际也只能去了解个 大概 。所以最近闲下来之后想要基于epoll机制实现一个比较有用的东西,刚好最近又想爬些东西,希望这次能够写一个高效一点的爬虫。
以前只看过一点点的nutch,自己写的就是用python的几个简单功能来爬,说真的一点技术含量都没,就是把网上的代码拿来改一改,跑一跑,效率没有,还经常出错。
Larbin is a web crawler (also called (web) robot, spider, scooter...). It is intended to fetch a large number of web pages to fill the database of a search engine. With a network fast enough, Larbin should be able to fetch more than 100 millions pages on a standard PC.
Larbin is (just) a web crawler, NOT an indexer. You have to write some code yourself in order to save pages or index them in a database.
下载: http://larbin.sourceforge.net/index-eng.html
安装
下载了larbin2.6.3,README里面的安装说明很简单,就是:
1
./
configure
2
make
但是实际需要做些准备工作的:
1
apt-get
install
xutils-dev
这样执行configure时才能用到makedepend命令。
make的时候出现若干错误:
1
parse.c: At top level:
2
parse.c:
113
:
13
: error: conflicting types
for
‘adns__parse_domain’
3
adns_status adns__parse_domain(adns_state ads,
int
serv, adns_query qu,
4
^
5
In
file
included from parse.c:
28
:
0
:
6
internal.h:
569
:
13
: note: previous declaration of ‘adns__parse_domain’ was here
7
adns_status adns__parse_domain(adns_state ads,
int
serv, adns_query qu,
这个简单,到internal.h把函数声明改成一样就行。
1
string
.
cc
:
6
:
22
: fatal error: iostream.h: No such
file
or directory
2
#include <iostream.h>
3
^
4
compilation terminated.
5
make
[
2
]: *** [
string
.o] Error
1
改成<iostream>就行了,用到c++的东西就加上std::也就没事了。不过有大量文件都出现这种情况。。。这一点还是要吐槽一下。
网上搜了一下,学习了几条命令用法。
1
sed
-e
'
s/iostream.h/iostream/g
'
-i
`
grep
-rl iostream.h *
`
2
sed
-e
'
s/cerr/std::cerr/g
'
-i
`
grep
-rl cerr *
`
3
sed
-e
'
s/endl/std::endl/g
'
-i
`
grep
-rl endl *`
grep -l表示只打印文件名。
运行
配置了一下larbin.conf和options.h,注释写得都很清楚,重新编译了一下,试一下京东,爬不下来。
京东的 robots.txt 是这样子的:
1
User-agent: *
2
Disallow: /?*
3
Disallow: /pop/*
.html
4
Disallow: /pinpai/*.html?*
5
User-
agent: EtaoSpider
6
Disallow: /
User-agent: * 这里的 * 代表的所有的搜索引擎种类。
Disallow: / 就是不允许爬取所有目录,看来这两家(一淘和京东)的确是在死磕。
照这样子看,应该是可以爬京东的,但就是没有数据,还是等我看完源码之后再试试。
改成爬http://demo.aisec.cn/demo/ ,就有数据了。
记
ok,总算是跑起来了,知道larbin有什么功能了,就可以开始看它的实现了。

