免费注册 查看新帖 |

Chinaunix

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

perl整站采集有什么好的方案? [复制链接]

论坛徽章:
7
戌狗
日期:2013-12-15 20:43:38技术图书徽章
日期:2014-03-05 01:33:12技术图书徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16赛季CBA联赛之青岛
日期:2016-03-17 20:36:13
11 [报告]
发表于 2013-05-23 14:25 |只看该作者
都是大牛。

论坛徽章:
3
摩羯座
日期:2013-09-04 12:01:36申猴
日期:2013-10-23 12:12:23CU十二周年纪念徽章
日期:2013-10-24 15:41:34
12 [报告]
发表于 2013-05-24 10:38 |只看该作者
http://search.cpan.org/~awncorp/Scrappy-0.94112090/lib/Scrappy.pm
上的第一个示例中看到个关键字href
  1. #!/usr/bin/perl
  2.     use Scrappy;

  3.     my  $scraper = Scrappy->new;
  4.    
  5.         $scraper->crawl('http://search.cpan.org/recent',
  6.             '/recent' => {
  7.                 '#cpansearch li a' => sub {
  8.                     print $_[1]->{href}, "\n";
  9.                 }
  10.             }
  11.         );
复制代码
原理是不是就是获取返回页面中href的链接,然后继续请求返回,重复循环直到找到想要的。

我设想过用lwp自己写个爬虫,循环的结束机制就是在所有获取的页面中没有最新的页面。
不知道我这个想法可不可行...

论坛徽章:
0
13 [报告]
发表于 2013-05-24 14:47 |只看该作者
python scrapy 肯定不是垃圾,perl 的 scrappy 好久没更新过。
你如果要自己用 perl 写的话, 参考scrapy的理念还是很好的。
自己学 python 也是可以的。

论坛徽章:
1
辰龙
日期:2014-05-15 19:37:15
14 [报告]
发表于 2013-05-24 18:54 |只看该作者
回复 12# grshrd49

用 Mojo 写了个爬虫的小例子,抄了一下云舒的 Bloom::Filter 模块的使用。
  1. #!/usr/bin/perl
  2. use strict;
  3. use Mojo::UserAgent;
  4. use Bloom::Filter;

  5. my $filter = Bloom::Filter->new(capacity => 100000, error_rate => 0.0001);
  6. my $ua = Mojo::UserAgent->new;

  7. my $delay = Mojo::IOLoop->delay;
  8. my $end = $delay->begin(0);

  9. my $callback;$callback = sub  {
  10.     my ($ua, $tx) = @_;
  11.     $end->() if !$tx->success;

  12.     $tx->res->dom->find("a[href]")->each(sub{
  13.             my $attrs  = shift->attrs;
  14.             my $newUrl = $attrs->{href};
  15.             next if $newUrl !~ /php-oa.com/;
  16.             if( !$filter->check($newUrl) ) {
  17.                 print $filter->key_count(), " ", $newUrl, "\n";
  18.                 $filter->add($newUrl);
  19.                 $ua->get($newUrl => $callback);
  20.             }   
  21.     });
  22.     $end->();
  23. };

  24. $ua->get($ARGV[0] => $callback);

  25. Mojo::IOLoop->start;
复制代码
使用直接存成文件,然后给上面的 php-oa.com 的域名修改掉,然后 perl ./t11.pl http://www.php-oa.com 这样就行了。

   

论坛徽章:
1
操作系统版块每日发帖之星
日期:2016-06-12 06:20:00
15 [报告]
发表于 2013-05-25 09:16 |只看该作者
回复 7# rubyish

....
  1.    Scrappy-0.94112090/t/00_test_function_page_content_type.t
  2. CPAN: File::Temp loaded ok (v0.22)
  3. CPAN: Parse::CPAN::Meta loaded ok (v1.40)
  4. CPAN: Module::CoreList loaded ok (v2.44)
  5. ---- Unsatisfied dependencies detected during ----
  6. ----     AWNCORP/Scrappy-0.94112090.tar.gz    ----
  7.     File::ShareDir::Install [build_requires]
  8. Shall I follow them and prepend them to the queue
  9. of modules we are processing right now? [yes]
  10.   AWNCORP/Scrappy-0.94112090.tar.gz
  11.   [configure_requires] -- NOT OK

  12.   CPAN.pm: Building A/AW/AWNCORP/Scrappy-0.94112090.tar.gz

  13. Can't locate File/ShareDir/Install.pm in @INC (@INC contains:
复制代码
cpan install   File::ShareDir::Install 以后提示
  1. Running install for module 'Scrappy'
  2. Running make for A/AW/AWNCORP/Scrappy-0.94112090.tar.gz
  3.   Has already been unwrapped into directory G:\Perl\cpan\build\Scrappy-0.94112090-BZtI9Z
  4.   'g:\perl\bin\perl.exe Makefile.PL' returned status 512, won't make
  5. Running make test
  6.   Make had some problems, won't test
  7. Running make install
  8.   Make had some problems, won't install
复制代码
这是什么回事?

论坛徽章:
1
操作系统版块每日发帖之星
日期:2016-06-12 06:20:00
16 [报告]
发表于 2013-05-25 09:24 |只看该作者
回复 14# iakuf


    Can't locate object method "delay" via package "Mojo::IOLoop" at  



Bloom::Filter is up to date (1.0).

 
Mojo::IOLoop is up to date (undef).


是不是我的Mojo安装得有问题?

论坛徽章:
1
操作系统版块每日发帖之星
日期:2016-06-12 06:20:00
17 [报告]
发表于 2013-05-25 09:43 |只看该作者
回复 12# grshrd49


    这是过滤策略

1 (按时间)该链接的响应头 lastmodify比如原来的新
2 (按内容)该页面的md5值 比原来的md5值不同
3  已经抓取过,不再处理

 
在抓取到的链接里,插入上面想要的过滤代码就可以

主要问题是怎么样根据配置来切换,perl如果动态根据配置,注入一段代码,这个好象比较麻烦 
 

论坛徽章:
1
辰龙
日期:2014-05-15 19:37:15
18 [报告]
发表于 2013-05-25 19:14 |只看该作者
回复 16# yakczh_cu
什么系统,什么 Perl 的版本?


   

论坛徽章:
1
操作系统版块每日发帖之星
日期:2016-06-12 06:20:00
19 [报告]
发表于 2013-05-25 23:20 |只看该作者
回复 18# iakuf


   
This is perl, v5.10.0 built for MSWin32-x86-multi-thread

win7

论坛徽章:
1
辰龙
日期:2014-05-15 19:37:15
20 [报告]
发表于 2013-05-26 08:41 |只看该作者
回复 19# yakczh_cu
windows 就不知道了。另外,这个最少要求好象是 5.10.1


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP