免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: 墨迹哥
打印 上一主题 下一主题

Perl爬虫,爬整站研究 [复制链接]

论坛徽章:
3
未羊
日期:2013-11-18 15:17:06酉鸡
日期:2013-12-06 17:07:16天蝎座
日期:2014-06-11 12:37:07
41 [报告]
发表于 2013-06-03 16:21 |只看该作者
回复 35# grshrd49


    这个404和500的问题很好解决的啊。。你先抓一个不存在的地址,捕获网站的404页面,然后进行爬虫的时候进行页面比对不就好了啊?
   之前那个啥,目录扫描的的脚本开发时就发现这个问题,挺蛋腾的。后来我就想到这么干。。

论坛徽章:
3
未羊
日期:2013-11-18 15:17:06酉鸡
日期:2013-12-06 17:07:16天蝎座
日期:2014-06-11 12:37:07
42 [报告]
发表于 2013-06-03 16:22 |只看该作者
回复 37# 撒哈拉里的鱼


    {:2_170:}  舜件惊讶了。。你出现了。。我还准备微薄勾引你一下。。。{:2_167:}

论坛徽章:
3
未羊
日期:2013-11-18 15:17:06酉鸡
日期:2013-12-06 17:07:16天蝎座
日期:2014-06-11 12:37:07
43 [报告]
发表于 2013-06-03 16:23 |只看该作者
回复 39# grshrd49


    我测过那个。。不行哇。。我回头再好好写写。。。蛋腾死了。。很多重复。。

论坛徽章:
3
未羊
日期:2013-11-18 15:17:06酉鸡
日期:2013-12-06 17:07:16天蝎座
日期:2014-06-11 12:37:07
44 [报告]
发表于 2013-06-03 16:24 |只看该作者
回复 36# iakuf


    主要我想知道那个容量的问题,你的想法是如何解决?例如抓取大型网站的思路。。
    这个东西挺有意思的。

论坛徽章:
1
辰龙
日期:2014-05-15 19:37:15
45 [报告]
发表于 2013-06-03 16:31 |只看该作者
回复 44# 墨迹哥
什么容量?


   

论坛徽章:
3
未羊
日期:2013-11-18 15:17:06酉鸡
日期:2013-12-06 17:07:16天蝎座
日期:2014-06-11 12:37:07
46 [报告]
发表于 2013-06-03 16:37 |只看该作者
回复 45# iakuf


    capacity => 100000  这个容量。。。
    还有一些别的刚报的问题。。想请教你解决bug思路.
第一个错误:这个是什么类型的错误?
  1. Timer 96f85ea9a9f21fdfea313a822cffdc66 failed: Unrecognised protocol tcp at /usr/local/share/perl/5.14.2/Mojo/IOLoop/Client.pm line 59.
  2. Timer 707d594955808dd0ec9dbb8f51875ef9 failed: Unrecognised protocol tcp at /usr/local/share/perl/5.14.2/Mojo/IOLoop/Client.pm line 59.
  3. Timer 70c022d81d23dd8620c80abf7996d862 failed: Unrecognised protocol tcp at /usr/local/share/perl/5.14.2/Mojo/IOLoop/Client.pm line 59.
复制代码
第二个错误:超出容量以后报的错误。。
  1. 1000 3 http://bbs.chinaunix.net/forum.php?mod=redirect&goto=findpost&ptid=3764816&pid=22310903
  2. Exceeded filter capacity at iakuf.pl line 38.
  3. 1000 3 http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=3764816&page=1&authorid=26148224
  4. Exceeded filter capacity at iakuf.pl line 38.
  5. 1000 3 http://bbs.chinaunix.net/space-uid-26148224.html
  6. Exceeded filter capacity at iakuf.pl line 38.
复制代码
这两个错误我想请教下。用什么方法能解决?

论坛徽章:
1
辰龙
日期:2014-05-15 19:37:15
47 [报告]
发表于 2013-06-03 16:40 |只看该作者
回复 46# 墨迹哥

capacity  这个参数设置更加大的值看看行不?
Bloom Filters 的资料看看仙子的文章
http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=601028


   

论坛徽章:
3
未羊
日期:2013-11-18 15:17:06酉鸡
日期:2013-12-06 17:07:16天蝎座
日期:2014-06-11 12:37:07
48 [报告]
发表于 2013-06-03 17:00 |只看该作者
回复 47# iakuf


    挺纠结。。你改完那个,爬163.COM不能正常结束。还有新的错误- - #
  错误一:
  1. 4780 1 http://analytics.163.com/ntes_dwld?prod=3gmarket&id=2911508&pf=1&cg=CA8MTG5J141&sign=a764b9708953839bbca57908500129e5&url=https%3A%2F%2Fitunes.apple.com%2Fcn%2Fapp%2Fid648243241%3Fmt%3D8
  2. Use of uninitialized value in hash element at /usr/local/share/perl/5.14.2/Mojo/Reactor/Poll.pm line 46.
  3. Use of uninitialized value $cb in method lookup at /usr/local/share/perl/5.14.2/Mojo/Reactor/Poll.pm line 109.
  4. Read failed: Can't locate object method "" via package "Mojo::Reactor::Poll" at /usr/local/share/perl/5.14.2/Mojo/Reactor/Poll.pm line 109.
  5. Use of uninitialized value in hash element at /usr/local/share/perl/5.14.2/Mojo/Reactor/Poll.pm line 46.
  6. Use of uninitialized value $cb in method lookup at /usr/local/share/perl/5.14.2/Mojo/Reactor/Poll.pm line 109.
  7. Read failed: Can't locate object method "" via package "Mojo::Reactor::Poll" at /usr/local/share/perl/5.14.2/Mojo/Reactor/Poll.pm line 109.
复制代码
错误二:
  1. Use of uninitialized value in addition (+) at /usr/local/share/perl/5.14.2/Mojo/Reactor/Poll.pm line 11.
  2. Use of uninitialized value in addition (+) at /usr/local/share/perl/5.14.2/Mojo/Reactor/Poll.pm line 11.
  3. Use of uninitialized value in addition (+) at /usr/local/share/perl/5.14.2/Mojo/Reactor/Poll.pm line 11.
  4. Use of uninitialized value in addition (+) at /usr/local/share/perl/5.14.2/Mojo/Reactor/Poll.pm line 11.

复制代码
我感觉是不是逼这咱们自己写纯PERL爬。。。这尼码的模块老是各种错误。。你有木有EMAIL。。。我们能EMAIL交流不?

论坛徽章:
3
未羊
日期:2013-11-18 15:17:06酉鸡
日期:2013-12-06 17:07:16天蝎座
日期:2014-06-11 12:37:07
49 [报告]
发表于 2013-06-03 17:01 |只看该作者
回复 47# iakuf


    最大值改成100W应该就够了。这个可以忽略。因为我觉得没有哪个站点能超100W个URL吧?

论坛徽章:
3
未羊
日期:2013-11-18 15:17:06酉鸡
日期:2013-12-06 17:07:16天蝎座
日期:2014-06-11 12:37:07
50 [报告]
发表于 2013-06-04 20:38 |只看该作者
本帖最后由 墨迹哥 于 2013-06-04 20:39 编辑

回复 36# iakuf


    @grshrd49 本想改写下之前云总那个做模块使用。。可是各种错误。。。你那个我没试过改写的效果。。。
  1. package Web_PageAnaly;

  2. use threads;
  3. use threads::shared;
  4. use Thread::Queue;
  5. use Thread::Semaphore;
  6. use Bloom::Filter;
  7. use URI::URL;
  8. use Web::Scraper;

  9. require Exporter;
  10. @ISA=(Exporter);
  11. @EXPORT=qw( Page_Analy ProcessUrl );
  12. share($host);
  13. $host = URI::URL->new($base_url)->host;
  14. $queue = Thread::Queue->new();
  15. $semaphore = Thread::Semaphore->new( $max_threads );
  16. $mutex = Thread::Semaphore->new( 1 );
  17. $filter = shared_clone( Bloom::Filter->new(capacity => 1000000, error_rate => 0.0001) );
  18. $res;
  19. $link;

  20. sub Web_PageAnaly::Page_Analy{
  21.   local($base_url)=shift;
  22.   local($max_threads)=shift;
  23.   $queue->enqueue( $base_url );
  24.   $filter->add( $base_url );
  25.   while( 1 ){
  26.         foreach ( threads->list(threads::joinable) ){
  27.                $_->join( );
  28.         }
  29.         my $item = $queue->pending();
  30.         if( $item == 0 ){
  31.                 my $active = threads->list(threads::running);
  32.                 if( $active == 0 ){
  33.                     print "All done!\n";
  34.                     last;
  35.                 }else{
  36.                     sleep 1;
  37.                     next;
  38.                 }
  39.         }
  40.         $semaphore->down;
  41.         threads->create( \&Web_PageAnaly::ProcessUrl );
  42.    }
  43.    foreach (threads->list()){
  44.       $_->join( );
  45.    }
  46. }
  47. sub Web_PageAnaly::ProcessUrl{
  48.      scraper = scraper{ process '//a', 'links[]' => '@href';};
  49.      while( my $url = $queue->dequeue_nb() ){
  50.          eval{$res = $scraper->scrape( URI->new($url) )->{'links'};};
  51.             if( $@ ){
  52.                   warn "$@\n";
  53.                   next;
  54.             }
  55.             next if (! defined $res );
  56.               foreach( @{$res} ) {
  57.                   $link = $_->as_string;
  58.                   $link = URI::URL->new($link, $url);
  59.                   next if( $link->scheme ne 'http' && $link->scheme ne 'https' );
  60.                   next if( $link->host ne $host );
  61.                   $link = $link->abs->as_string;
  62.                      if( $link =~ /(.*?)#(.*)/ ){
  63.                            $link = $1;
  64.                      }
  65.                      next if( $link =~ /.(jpg|png|bmp|mp3|wma|wmv|gz|zip|rar|iso|pdf)$/i );
  66.                         $mutex->down();
  67.                      if( ! $filter->check($link) ){
  68.                                 print $filter->key_count(), " ", $link, "\n";
  69.                                 open FILE,">>$host.html" or die $!;
  70.                                 print FILE ("<a href='$link'>$link</a>\n");
  71.                                 close(FILE);
  72.                                 $filter->add($link);
  73.                                 $queue->enqueue($link);
  74.                         }
  75.                         $mutex->up();
  76.                         undef $link;
  77.                 }
  78.                 undef $res;
  79.         }
  80.         undef $scraper;
  81.         $semaphore->up();
  82. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP