perl LWP::Simple分析腾讯MV点击量

该脚本用于计算腾讯MV前100页的实时点击量:

[root@dou ~]# cat tengxun.pl
#!/usr/bin/perl -w
# This script is used to count the numbers of page views of tengxun's yinyue MV item.

use strict;
use LWP::Simple;
use Encode;

my $num;
my $total;
my $filetmp = "tmpfile";
my @nums = (0..99);
my @firstnums = (0..9) x 10;
my $firstnum = 0;

foreach my $nums (@nums) {
        my $url = "http://v.qq.com/mvlist/$firstnums[$firstnum]/22\_-1\_-1\_-1\_-1\_1\_$nums\_0\_28.html";
        my $file = "output";
        open (my $out,'>',"$file") or die "can't open file $file: $!\n";
        my $contents = get($url);
        $contents = encode_utf8($contents);
        print $out $contents;
        close $out;
        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 open file $filetmp: $!\n";
                print $tmpfile "$num\n";
                $total += $num;
        }
        $firstnum += 1;
        close $in;
}
print "$total\n";

你可能感兴趣的:(视频,perl,点击量,LWP::Simple)