加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl LWP::UserAgent抓捕腾讯音乐MV点击量

发布时间:2020-12-15 21:01:45 所属栏目:大数据 来源:网络整理
导读:抓捕腾讯音乐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"

抓捕腾讯音乐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 "$numn"; ??????????????????????? $total += $num; ??????????????????? } ??????? $firstnum += 1; ??????? close $in; ??????? } else { ??????????????? print "sorry,request failed at [ $firstnum ] -> [ $nums ]n";; ??????? } } print "$totaln";

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读