Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2085447
  • 博文数量: 249
  • 博客积分: 1305
  • 博客等级: 军士长
  • 技术积分: 4733
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-17 10:37
个人简介

不懂的东西还有很多,随着不断的学习,不懂的东西更多,无法消灭更多不懂的东西,那就不断的充实自己吧。 欢迎关注微信公众号:菜鸟的机器学习

文章分类

全部博文(249)

文章存档

2015年(1)

2014年(4)

2013年(208)

2012年(35)

2011年(1)

分类: 网络与安全

2012-10-30 20:47:48

   由于以前没有接触过网络爬虫,对网络爬虫仅仅停留在听过,具体怎么样不天清楚。正好,需要完成某作业,我想这样可以了解了解这方面的知识了。

   从网上看了很多网络爬虫,最后,选择了Larbin,因为这是用C++写的,对于源码可以相对比较容易的看懂。
   
   现在,把安装过程和相关的配置记录下来,省的以后用的时候还得查找资料。

一、Larbin的安装

   从官网上获取源码包:larbin.2.6.3。
   
   现在开始正式安装。
   1、 ./configure
   2、 gmake debug(debug:调试安装,当然,也可以不使用该选项)

   但是,安装过程中出现了错误,如下所示。

   1> 错误1
  1. parse.c:115: error: conflicting types for 'adns__parse_domain'
  2. internal.h:571: error: previous declaration of 'adns__parse_domain' was here
  3. parse.c:115: error: conflicting types for 'adns__parse_domain'
  4. internal.h:571: error: previous declaration of 'adns__parse_domain' was here
  5. gmake[1]: *** [parse.o] 错误 1
  6. gmake[1]: Leaving directory `/home/leo/leo/larbin-2.6.3/adns'
  7. make: *** [all] 错误 2
    解决方案:
    函数原型和定义不一致这个好改:
    打开./adns/internal.h文件,把568-571行直接注释掉就行了。

   2> 错误2  
  1. -bash:./configure:command not found
    解决方案:
    我上网查了查,执行了命令:chmod +x configure,然后就可以了。不晓得为什么。

二、Larbin的配置说明

1、larbin.conf文件

  1. ###############################################
  2. //客户端标记,当对其他网站抓取时,被抓取的网站知道是什么抓取的

  3. UserAgent larbin_2.6.3

  4. ############################################
  5. # What are the inputs and ouputs of larbin
  6. # port on which is launched the http statistic webserver
  7. # if unset or set to 0, no webserver is launched

  8. //用于运行的http web服务器的端口号(larbin运行时访问,设置为http_port 8081).如果将端口设为0,则不会启动web服务器。通过这个可以查看爬行结果。

  9. httpPort 8081

  10. # port on which you can submit urls to fetch
  11. # no input is possible if you comment this line or use port 0

  12. //你要爬取url的端口。如果注释掉或设为0,则可能没有任何输入。如果通过手动或者程序提交爬取的//urls,则必须练就到计算机的TCP端口1976,即设为:inputPort 1976,可以添加爬行的url。

  13. #inputPort 1976

  14. ############################################
  15. # parameters to adapt depending on your network
  16. # Number of connexions in parallel (to adapt depending of your network speed)
  17. //并行爬取网页的数量,根据自己环境的网速调解,如果超时太多,则要降低这个并行数量

  18. pagesConnexions 100

  19. # Number of dns calls in parallel
  20. //并行DNS域名解析的数量。

  21. dnsConnexions 5

  22. # How deep do you want to go in a site
  23. //对一个站点的爬取的深度

  24. depthInSite 5

  25. # do you want to follow external links
  26. //不允许访问外部链接。如果设置则只可访问同一主机的连接
  27. #noExternalLinks

  28. # time between 2 calls on the same server (in sec) : NEVER less than 30
  29. //访问同一服务器的时间间隔。不可低于30s,建议60s
  30. waitDuration 60

  31. # Make requests through a proxy (use with care)
  32. //是否用代理连接,如果用,则要设置、可以不用尽量不要用,这个选项要谨慎
  33. #proxy www 8080

  34. ##############################################
  35. # now, let's customize the search

  36. # first page to fetch (you can specify several urls)
  37. //开始爬取的URL
  38. startUrl http://slashdot.org/

  39. # Do you want to limit your search to a specific domain ?
  40. # if yes, uncomment the following line
  41. //这个选项设置了,则不可以爬行指定的特殊域名
  42. #limitToDomain .fr .dk .uk end

  43. # What are the extensions you surely don't want
  44. # never forbid .html, .htm and so on : larbin needs them
  45. //不想要的扩展名文件。一定不要禁止.html、.htm.larbin爬取的就是它们。禁止也是无效的
  46. forbiddenExtensions
  47. .tar .gz .tgz .zip .Z .rpm .deb
  48. .ps .dvi .pdf
  49. .png .jpg .jpeg .bmp .smi .tiff .gif
  50. .mov .avi .mpeg .mpg .mp3 .qt .wav .ram .rm
  51. .jar .java .class .diff
  52. .doc .xls .ppt .mdb .rtf .exe .pps .so .psd
  53. end

2、options.h

2.1 输出模式

  1. // Select the output module you want to use

  2. //默认模式。什么也不输出,不要选择这个
  3. #define DEFAULT_OUTPUT // do nothing...
  4. //简单保存,存在save/dxxxxx/fyyyyy文件中,每个目录下2000个文件
  5. //#define SIMPLE_SAVE // save in files named save/dxxxxxx/fyyyyyy
  6. //镜像方式存储。按网页的层次存储,可以作为网页的字典。
  7. //#define MIRROR_SAVE // save in files (respect sites hierarchy)
  8. //状态输出。在网页上进行状态输出,可以查看output.html查看结果
  9. //#define STATS_OUTPUT // do some stats on pages
    这些模式被定制在src/type.h中,可以在src/interf/useroutput.cc中定制自己的输出模式。
   这个文件中还有很多相关配置,更改后,需要重新编译。
  
2.2 特定查询

  1. // Set up a specific search
  2. //设置特定的查询
  3. //#define SPECIFICSEARCH
  4. //内容类型
  5. //#define contentTypes ((char *[]) { "audio/mpeg", NULL })
  6. //文件扩展。用于查询速度,不涉及类型,类型由上一个决定
  7. //#define privilegedExts ((char *[]) { ".mp3", NULL })

2.3 设置完要设置特定文件的管理

  1. #define DEFAULT_SPECIFIC //默认管理方式。 作为html有限制除了被解析。

  2. // 存储特定文件。 允许将文件存储在硬盘上 文件可以很大在src/types.h 可以具体设置。
  3. #define SAVE_SPECIFIC 

  4. //动态存储模式。对于较大的文件动态的分配buffer。
  5. #define DYNAMIC_SPECIFIC 
     可以通过"src/fetch/specbuf.cc" and "src/fetch/specbuf.h" 定义特定文件的管理方式。

2.4 你要爬虫做什么

  1. //不继续子链接。不设置此项则html页不被解析链接也不会爬子链接。通过输入系统添加url时很有用
  2. #define FOLLOW_LINKS

  3. //每个网页中包含的子链接的列表。在"useroutput.cc" 用page->getLinks() 访问此信息。
  4. #define LINKS_INFO 

  5. //url标签。设置此项url有一个int(默认为0)。使用输入系统统时应该给定一个int。可以通过其获取u//rl。可以重定向。
  6. #define URL_TAGS

  7. //不允许重复。如果设置则遇到相同网页但已遇到过时则不管。
  8. #define NO_DUP

  9. //结束退出。没有url可爬取时是否退出。设置则退出。
  10. #define EXIT_AT_END 

  11. //抓取网页中的图片。设置了此项则要更新larbin.conf中禁止项。
  12. #define IMAGES

  13. //抓取任何类型网页不管其的类型。设置要更新larbin.conf。
  14. #define ANYTYPE

  15. //要larbin管理cookies。只简单实现但很有用。
  16. #define COOKIES

2.5 其他选项说明

  1. #define CGILEVEL 1        //定于选项及其参数。用于对爬行的url的限制。

  2. #define MAXBANDWIDTH 200000  //larbin使用的带宽大小。不设置则不限带宽。

  3. #define DEPTHBYSITE          //当url链接到其他站点时新rul的深度是已被初始化的。

2.6 效率和特征

  1. //是否为输入制定一个专用线程。当你在useroutput.cc定义自己的代码时必须设置此项。
  2. #define THREAD_OUTPUT

  3. //重启位置记录表。设置此项时可以从上次终止处继续爬取。使用-scratch 选项从上次结束处重启。
  4. #define RELOAD

2.7 Larbin怎么工作

  1. #define NOWEBSERVER   //不启动服务器。不运行线程时很有用

  2. #define GRAPH //是否在状态也使用柱状图。

  3. #define NDEBUG //不启动调试信息。

  4. #define NOSTATS //不启动状态输出。

  5. #define STATS //启动状态输出。运行时每个一段时间就会输出抓取的状态

  6. #define BIGSTATS //在标准输出上显示每个被抓去的网页名字。会降低larbin速度

  7. #define CRASH //用于报告严重的bugs用。以gmake debug模式编译时使用。

   

   备注:关于larbin配置文件详解,转自:http://terry831010.blog.163.com/blog/static/69161171201227111635189/
   感谢作者。




梦醒潇湘love
      2012/10/30 22:07

    
    
阅读(10313) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~