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

Perl 按地区统计访问次数

发布时间:2020-12-15 23:46:16 所属栏目:大数据 来源:网络整理
导读:#!/usr/local/bin/perluse LWP::Simple qw(get);use Encode;use Encode::CN;use JSON; use URI::Escape;open (LOG,"","129_2");while (LOG){$ip = $_;print "hostip is $_n";$host = "http://ip.taobao.com/service/getIpInfo.php?ip=$_";$content = get($h
#!/usr/local/bin/perl

use LWP::Simple qw(get);


use Encode;
use Encode::CN;
use JSON; 
use URI::Escape;
open (LOG,"<","129_2");
while (<LOG>){
$ip = $_;
print "hostip is $_n";
$host = "http://ip.taobao.com/service/getIpInfo.php?ip=$_";
$content = get($host);
$content =~ s/u([0-9a-fA-F]{4})/pack("U",hex($1))/eg;  
$content=encode(gbk,$content);
if ($content =~ /(.*?)"region":(.*?),"region_id"(.*?)"city":(.*?),(.*?)/){ 
   $a = $2;
   $b = $4;
   $a =~ s/"//g ;
   $b =~ s/"//g ;
if ($b ){$city = $b;}else{
   $city = $a;};
   $city =~ s/"//g ; 
   print "$city is $cityn"; 
} 
   open (B,">>x.log");
    print B ("$city  $ipn");
   print "$contentn"};

 open (LOG,"x.log");  
                    while (<LOG>) {  
                    chomp;  
		     $var= (split / /,$_)[0]; 
		     $log{$var}++;  
                    }

		    while(my($city,$times) = each %log) {  
                         print "$city  $timesn";
			 open (C,">>y.log");
			 print B ("$city  $timesn");
                              }  

(编辑:李大同)

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

    推荐文章
      热点阅读