perl LWP::Simple分析土豆视频点击量

#!/usr/bin/perl -w
# This script is used to count the numbers of page views of tudou's yinyue item.

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

my $num;
my $total;
my @nums = (1..50);

foreach my $num (@nums) {
        my $url = "http://music.tudou.com/labeltop/zcakqzfjz19zdwyq_s0p$num.html";
        my $file = "output";
        open (my $out,'>',"$file");
        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 /播放/ and /播客/;
                /.*<li>播放: ([\d|,]*\d+)<\/li>.*/;
                $num = $1;
                $num =~ s/,//g;
                my $filetmp = "tmpfile";
                open (my $tmpfile,'>>',"$filetmp") or die "can't open file $filetmp: $!\n";
                print $tmpfile "$num\n";
                $total += $num;
        }
        close $in;
}
print "$total\n";

你可能感兴趣的:(perl,LWP::Simple,抓捕网页)