介绍html
功能:网络爬虫java
开发语言:c++ios
开发者:Sébastien Ailleret(法国)c++
特色:只抓取网页,高效(一个简单的larbin的爬虫能够天天获取500万的网页)web
安装浏览器
安装平台:Ubuntu 12.10服务器
下载:http://sourceforge.net/projects/larbin/files/larbin/2.6.3/larbin-2.6.3.tar.gz/downloadcookie
安装:网络
tar -zxvf larbin-2.6.3.tar.gz cd larbin-2.6.3 ./configure make
期间会出现错误,解决less
1. adns文件夹下internal.h文件569-571行:
adns_status adns__parse_domain(adns_state ads, int serv, adns_queryqu, vbuf *vb, parsedomain_flags flags, const byte *dgram, int dglen, int *cbyte_io, int max);
改成
adns_status adns__parse_domain(adns_state ads, int serv, adns_query qu, vbuf *vb, adns_queryflags flags, const byte *dgram, int dglen, int *cbyte_io, int max);
2. 输入sudo ./congure 出现错误
make[2]: 正在进入目录 `/home/byd/test/larbin-2.6.3/src/utils' makedepend -f- -I.. -Y *.cc 2> /dev/null > .depend make[2]: *** [dep-in] 错误 127 make[2]:正在离开目录 `/home/byd/test/larbin-2.6.3/src/utils' make[2]: 正在进入目录 `/home/byd/test/larbin-2.6.3/src/interf' <span style="color: #ff0000;"><strong>makedepend</strong></span> -f- -I.. -Y *.cc 2> /dev/null > .depend make[2]: *** [dep-in] 错误 127 make[2]:正在离开目录 `/home/byd/test/larbin-2.6.3/src/interf' make[2]: 正在进入目录 `/home/byd/test/larbin-2.6.3/src/fetch' makedepend -f- -I.. -Y *.cc 2> /dev/null > .depend make[2]: *** [dep-in] 错误 127 make[2]:正在离开目录 `/home/byd/test/larbin-2.6.3/src/fetch' make[1]: *** [dep] 错误 2 make[1]:正在离开目录 `/home/byd/test/larbin-2.6.3/src' make: *** [dep] 错误 2
上边提示makedepend 有问题,因而输入makedepend,提示
makedepend 没安装,可是能够经过
sudo apt-get install xutils-dev
ok了。
3. 到/usr/include/c++/下CP一份iostream文件到larbin的src目录下。并将其名改成iostream.h,在文件中添加一句
using namespace std;
而后,继续
make
运行
./larbin
能够在浏览器上输入"localhost:8081"看当前爬虫的运行情况
终止
ctrl+c
重启
./larbin -scratch
再次启动larbin时出现错误(只输入命令 ./larbin)
larbin_2.6.3 is starting its search Unable to get the socket for the webserver (8081) : Address already in use
缘由
当客户端保持着与服务器端的链接,这时服务器端断开,再开启服务器时会出现: Address already in use
解决
netstat -anp | more
能够看到(以下图),杀死进程便可
kill -9 18066
其中
配置
一、larbin.conf文件
############################################### //客户端标记,当对其余网站抓取时,被抓取的网站知道是什么抓取的 UserAgent larbin_2.6.3 ############################################ # What are the inputs and ouputs of larbin # port on which is launched the http statistic webserver # if unset or set to 0, no webserver is launched //用于运行的http web服务器的端口号(larbin运行时访问http://localhost:8081/,设置为http_port 8081).若是将端口设为0,则不会启动web服务器。经过这个能够查看爬行结果 httpPort 8081 # port on which you can submit urls to fetch # no input is possible if you comment this line or use port 0 //你要爬取url的端口。若是注释掉或设为0,则可能没有任何输入。若是经过手动或者程序提交爬取的//urls,则必须练就到计算机的TCP端口1976,即设为:inputPort 1976,能够添加爬行的url。 #inputPort 1976 ############################################ # parameters to adapt depending on your network # Number of connexions in parallel (to adapt depending of your network speed) //并行爬取网页的数量,根据本身环境的网速调解,若是超时太多,则要下降这个并行数量 pagesConnexions 100 # Number of dns calls in parallel //并行DNS域名解析的数量。 dnsConnexions 5 # How deep do you want to go in a site //对一个站点的爬取的深度 depthInSite 5 # do you want to follow external links //不容许访问外部连接。若是设置则只可访问同一主机的链接 #noExternalLinks # time between 2 calls on the same server (in sec) : NEVER less than 30 //访问同一服务器的时间间隔。不可低于30s,建议60s waitDuration 60 # Make requests through a proxy (use with care) //是否用代理链接,若是用,则要设置、能够不用尽可能不要用,这个选项要谨慎 #proxy www 8080 ############################################## # now, let's customize the search # first page to fetch (you can specify several urls) //开始爬取的URL startUrl http://slashdot.org/ # Do you want to limit your search to a specific domain ? # if yes, uncomment the following line //这个选项设置了,则不能够爬行指定的特殊域名 #limitToDomain .fr .dk .uk end # What are the extensions you surely don't want # never forbid .html, .htm and so on : larbin needs them //不想要的扩展名文件。必定不要禁止.html、.htm.larbin爬取的就是它们。禁止也是无效的 forbiddenExtensions .tar .gz .tgz .zip .Z .rpm .deb .ps .dvi .pdf .png .jpg .jpeg .bmp .smi .tiff .gif .mov .avi .mpeg .mpg .mp3 .qt .wav .ram .rm .jar .java .class .diff .doc .xls .ppt .mdb .rtf .exe .pps .so .psd end
二、options.h
2.1 输出模式
// Select the output module you want to use //默认模式。什么也不输出,不要选择这个 #define DEFAULT_OUTPUT // do nothing...
//简单保存,存在save/dxxxxx/fyyyyy文件中,每一个目录下2000个文件 //#define SIMPLE_SAVE // save in files named save/dxxxxxx/fyyyyyy
//镜像方式存储。按网页的层次存储,能够做为网页的字典。 //#define MIRROR_SAVE // save in files (respect sites hierarchy)
//状态输出。在网页上进行状态输出,能够查看http://localhost:8081/output.html查看结果 //#define STATS_OUTPUT // do some stats on pages
// Set up a specific search //设置特定的查询 //#define SPECIFICSEARCH //内容类型 //#define contentTypes ((char *[]) { "audio/mpeg", NULL }) //文件扩展。用于查询速度,不涉及类型,类型由上一个决定 //#define privilegedExts ((char *[]) { ".mp3", NULL })
2.3 设置完要设置特定文件的管理
#define DEFAULT_SPECIFIC //默认管理方式。 做为html有限制除了被解析。 //存储特定文件。 容许将文件存储在硬盘上 文件能够很大在src/types.h 能够具体设置。 #define SAVE_SPECIFIC //动态存储模式。对于较大的文件动态的分配buffer。 #define DYNAMIC_SPECIFIC
能够经过"src/fetch/specbuf.cc" and "src/fetch/specbuf.h" 定义特定文件的管理方式。
2.4 你要爬虫作什么
//不继续子连接。不设置此项则html页不被解析连接也不会爬子连接。经过输入系统添加url时颇有用 #define FOLLOW_LINKS //每一个网页中包含的子连接的列表。在"useroutput.cc" 用page->getLinks() 访问此信息。 #define LINKS_INFO //url标签。设置此项url有一个int(默认为0)。使用输入系通通时应该给定一个int。能够经过其获取u//rl。能够重定向。 #define URL_TAGS //不容许重复。若是设置则遇到相同网页但已遇到过期则无论。 #define NO_DUP //结束退出。没有url可爬取时是否退出。设置则退出。 #define EXIT_AT_END //抓取网页中的图片。设置了此项则要更新larbin.conf中禁止项。 #define IMAGES //抓取任何类型网页无论其的类型。设置要更新larbin.conf。 #define ANYTYPE //要larbin管理cookies。只简单实现但颇有用。 #define COOKIES
2.5 其余选项说明
#define CGILEVEL 1 //定于选项及其参数。用于对爬行的url的限制。 #define MAXBANDWIDTH 200000 //larbin使用的带宽大小。不设置则不限带宽。 #define DEPTHBYSITE //当url连接到其余站点时新rul的深度是已被初始化的。
2.6 效率和特征
//是否为输入制定一个专用线程。当你在useroutput.cc定义本身的代码时必须设置此项。 #define THREAD_OUTPUT //重启位置记录表。设置此项时能够从上次终止处继续爬取。使用-scratch 选项从上次结束处重启。 #define RELOAD
2.7 Larbin怎么工做
#define NOWEBSERVER //不启动服务器。不运行线程时颇有用 #define GRAPH //是否在状态也使用柱状图。 #define NDEBUG //不启动调试信息。 #define NOSTATS //不启动状态输出。 #define STATS //启动状态输出。运行时每一个一段时间就会输出抓取的状态。 #define BIGSTATS //在标准输出上显示每一个被抓去的网页名字。会下降larbin速度 #define CRASH //用于报告严重的bugs用。以gmake debug模式编译时使用。
参考