perl数据提取

#!/usr/local/bin/perl -w
# author by luyi
use strict;
#use LWP::Simple qw(getstore); 


my $obj_file="/home/getdata/dota2_html.txt";
my $info="/tmp/get_dota2_players.info";
my $all_data="/export/remotedata/dota2/wget_dota2_players.txt"; 
my $address='http://www.dota2.com/overview?u=public&appid=570&internal=1';
my $cmd=qx(which wget);
chomp($cmd);
my $curtime=qx(date +%F' '%T);
chomp($curtime);
my $curdate=qx(date +%F);
chomp($curdate);
my $version="20131115";




if (-s $all_data){
               `cp $all_data /export/remotedata/dota2/wget_dota2_players_old.txt`;
}
              
unlink $obj_file if (-f $obj_file);


qx($cmd "$address" -a $info -O $obj_file);
my $status="$?";
print "$cmd $address -a $info -O $obj_file\n";


qx(/usr/bin/dos2unix $obj_file);
open(INFO,">>$info") or die "Can't open $info : $!";
open(DOTA2,"$obj_file") or die "Can't open $obj_file : $!";
open(RST,">>$all_data") or die "Can't open $all_data : $!";


if("$status" ne "0")
{
#       print "$curtime\tPerfectWorldTelecom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
#       print RST "$curtime\tPerfectWorldTelecom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
#       print "$curtime\tPerfectWorldUnicom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
#       print RST "$curtime\tPerfectWorldUnicom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";


#       print "$curtime\tPerfectWorldTelecom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
#       print RST "$curtime\tPerfectWorldTelecom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
#       print "$curtime\tPerfectWorldUnicom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
#       print RST "$curtime\tPerfectWorldUnicom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";


        print "$curtime\tPerfectWorldTelecom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
        print RST "$curtime\tPerfectWorldTelecom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
        print "$curtime\tPerfectWorldUnicom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
        print RST "$curtime\tPerfectWorldUnicom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
        exit;
}


my $old_delim=$/;
$/=undef; 
$_ = <DOTA2>;




#if (/.+Players.+\<th\>PerfectWorldTelecom<\/th\>\n.+\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+PerfectWorldUnicom.+<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+Totals.+\<h2\>Servers.+Game\s+Servers.+\<th\>PerfectWorldTelecom<\/th\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+PerfectWorldUnicom.+<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+Totals.+Proxy\s+Servers.+\<th\>PerfectWorldTelecom<\/th\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+PerfectWorldUnicom.+<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+Totals/s){
#if (/.+Players.+\<th\>PerfectWorldTelecom<\/th\>\n.+\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+PerfectWorldUnicom.+<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+Totals.+\<h2\>Servers.+Game\s+Servers.+\<th\>PerfectWorldTelecom<\/th\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+PerfectWorldUnicom.+<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+Totals.+Proxy\s+Servers.+/s){




if (/.+Players.+\<th\>PerfectWorldTelecom<\/th\>\n.+\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+PerfectWorldUnicom.+<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+Totals.+\<h2\>Servers.+\<th\>PerfectWorldTelecom<\/th\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+PerfectWorldUnicom.+<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>\n\s+\<td\>(\d+)\<\/td\>.+Totals/s){
        #Region Total In Queue In Match In Solo Match In Practice In Tournament In Coop In Team Match Spectating Idle 
        # print "$curtime\tPerfectWorldTelecom\t${version}\t$1\t$2\t$3\t$4\t$5\t$6\t$7\t$8\t$9\t$10\t$21\t$22\t$25\t$26\n";
        #print RST "$curtime\tPerfectWorldTelecom\t${version}\t$1\t$2\t$3\t$4\t$5\t$6\t$7\t$8\t$9\t$10\t$21\t$22\t$25\t$26\n";
        #print "$curtime\tPerfectWorldUnicom\t${version}\t$11\t$12\t$13\t$14\t$15\t$16\t$17\t$18\t$19\t$20\t$23\t$24\t$27\t$28\n";
        #print RST "$curtime\tPerfectWorldUnicom\t${version}\t$11\t$12\t$13\t$14\t$15\t$16\t$17\t$18\t$19\t$20\t$23\t$24\t$27\t$28\n";
        #print "$curtime\tPerfectWorldTelecom\t${version}\t$1\t$2\t$3\t$4\t$5\t$6\t$7\t$8\t$9\t$10\t$21\t$22\n";
        #print RST "$curtime\tPerfectWorldTelecom\t${version}\t$1\t$2\t$3\t$4\t$5\t$6\t$7\t$8\t$9\t$10\t$21\t$22\n";
        #print "$curtime\tPerfectWorldUnicom\t${version}\t$11\t$12\t$13\t$14\t$15\t$16\t$17\t$18\t$19\t$20\t$23\t$24\n";
        #print RST "$curtime\tPerfectWorldUnicom\t${version}\t$11\t$12\t$13\t$14\t$15\t$16\t$17\t$18\t$19\t$20\t$23\t$24\n";
        print "$curtime\tPerfectWorldTelecom\t${version}\t$1\t$2\t$3\t$4\t$5\t$6\t$7\t$8\t$9\t$10\t$21\t$22\t$23\n";
        print RST "$curtime\tPerfectWorldTelecom\t${version}\t$1\t$2\t$3\t$4\t$5\t$6\t$7\t$8\t$9\t$10\t$21\t$22\t$23\n";
        print "$curtime\tPerfectWorldUnicom\t${version}\t$11\t$12\t$13\t$14\t$15\t$16\t$17\t$18\t$19\t$20\t$24\t$25\t$26\n";
        print RST "$curtime\tPerfectWorldUnicom\t${version}\t$11\t$12\t$13\t$14\t$15\t$16\t$17\t$18\t$19\t$20\t$24\t$25\t$26\n";
}else{
        #print "$curtime\tPerfectWorldTelecom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
        #print RST "$curtime\tPerfectWorldTelecom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
        #print "$curtime\tPerfectWorldUnicom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
        #print RST "$curtime\tPerfectWorldUnicom\t${version}\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\n";
        print INFO "$curtime : The dota2 web information format have changed!\n";
        print "$curtime : The dota2 web information format have changed!\n\n";
}
close(DOTA2);
close(INFO);


close(RST);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值