處理待分析日誌中特徵為中英文混現的方法

來源:互聯網
上載者:User

如:

待分析的log資訊會出現:

(a)"http://fenlei.hudong.com/%E7%89%B9%E6%AD%A5%E4%B8%AD%E5%9B%BD%E5%A4%A7%E5%AD%A6%E7%94%9F5%E4%BA%BA%E5%88%B6%E8%B6%B3%E7%90%83%E8%81%94%E8%B5%9B/";

(b)"http://fenlei.hudong.com/特步中國大學生5人制足球聯賽/"

待匹配的特徵資訊為:"http://fenlei.hudong.com/特步中國大學生5人制足球聯賽/"

這兩項怎麼改變編碼方式能正確的統計到流量資訊呢?

1、開始使用如下方法:

將待匹配的特徵的utf8編碼寫出來與log資訊來匹配:

my $fl1 = "http://fenlei.hudong.com/%E7%89%B9%E6%AD%A5%E4%B8%AD%E5%9B%BD%E5%A4%A7%E5%AD%A6%E7%94%9F5%E4%BA%BA%E5%88%B6%E8%B6%B3%E7%90%83%E8%81%94%E8%B5%9B/";my $fl2 = "http://fenlei.hudong.com/%E7%89%B9%E6%AD%A5/";my $fl3 = "http://fenlei.hudong.com/%E7%89%B9%E6%AD%A5%E5%8D%81%E5%B9%B4/";if($ref eq $fl1 || $ref eq $fl2 || $ref eq $fl3){$fenleiInfo{$ref}++;$totalpv++;}

這種弊端是,log資訊中出現的情況(b)將漏掉統計。


2、後來想到是編碼問題,然後改用下面的方法

my $fl1= "http://fenlei.hudong.com/特步中國大學生5人制足球聯賽/";my $fl2= "http://fenlei.hudong.com/特步/";my $fl3= "http://fenlei.hudong.com/特步十年/";$ref = decode('utf8',$ref);if($ref eq $fl1 || $ref eq $fl2 || $ref eq $fl3){$fenleiInfo{$ref}++;$totalpv++;}

這種弊端是,log資訊中出現的情況(a)將漏掉統計。

3、看來以上兩種方法都無法完美的解決這種中英文混合出現的情況,於是想到了使用方法:uri_unescape。

於是問題解決了,得到了以上1、2的結果之和。

use URI::Escape;my $fl1= "http://fenlei.hudong.com/特步中國大學生5人制足球聯賽/";my $fl2= "http://fenlei.hudong.com/特步/";my $fl3= "http://fenlei.hudong.com/特步十年/";my $ref1 = "";if($ref =~ /http:\/\/fenlei.hudong.com\//){$ref1 = uri_unescape($ref);#decode('utf8',$ref);$ref1 = decode('utf8',$ref1);}if($ref1 eq $fl1 || $ref1 eq $fl2 || $ref1 eq $fl3){$fenleiInfo{$ref1}++;$totalpv++;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.