抓捕腾讯音乐MV前100页的点击量
[root@dou ~]# cat lwp.pl
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use Encode;
my $num;
my $total;
my @nums = (0..99);
my @firstnums = (0..9) x 10;
my $firstnum = 0;
my $HTML_result;
my $file = "tmp1";
my $filetmp = "tmpfile";
my $ua = LWP::UserAgent->new;
$ua->timeout(3);
foreach my $nums (@nums) {
my $url = "http://v.qq.com/mvlist/$firstnums[$firstnum]/22\_-1\_-1\_-1\_-1\_1\_$nums\_0\_28.html"; my $response = $ua->get($url); if ($response->is_success) { $HTML_result = encode_utf8($response->decoded_content); open(my $fh,'>',"$file") or dIE "can't create file $file:$!\n"; print $fh $HTML_result; close $fh; open(my $in,'<',"$file") or dIE "can't open file $file: $!\n"; while(<$in>) { next unless /_total_vIEw/; /.*"_total_vIEw">(\d+)<\/span>.*/; $num = $1; open(my $tmpfile,'>>',"$filetmp")or dIE "can't create file $filetmp:$!\n"; print $tmpfile "$num\n"; $total += $num; } $firstnum += 1; close $in; } else { print "sorry,request Failed at [ $firstnum ] -> [ $nums ]\n";; } } print "$total\n";
以上是内存溢出为你收集整理的perl LWP::UserAgent抓捕腾讯音乐MV点击量全部内容,希望文章能够帮你解决perl LWP::UserAgent抓捕腾讯音乐MV点击量所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)