Python apache log gets Baidu keyword search source

Source: Internet
Author: User
Tags php tutorial apache log

Python apache log gets Baidu keyword search source
#!/usr/bin/python
#-#-Coding:utf-8-*-

Import OS, base64, RE, Fnmatch, Imghdr, Shutil, Pprint, Urlparse

Log = "SEO tutorial. Log"
reader = open (log, ' R ')
Config = {' S0 ': {' h ': ' www.google.com.hk ', ' Q ': ' Q '}, ' s1 ': {' h ': ' www.baidu.com ', ' Q ': ' Wd|word '}, ' S3 ': {' h ': ' Www.soso.com ', ' Q ': ' W '}}
def get_q (x):
For i,j in Config.items ():
Str_q = j[' q '].split (' | ')
if X.netloc = = j[' h ']:
Return str_q

For line in Reader.xreadlines ():
p = re.compile ('. * "Get (/seo/t.php tutorial?) * http/1.1 ". *", Re.ignorecase)
m = P.match (line)
If M:
s_t = M.group (1)
S_t_u = Urlparse.urlparse (s_t)

S_t_u_qs = Urlparse.parse_qs (s_t_u.query,true)
#print s_t_u_qs[' ref '][0]
ref = Urlparse.urlparse (str (s_t_u_qs[' ref '][0]))

Ref_qs = Urlparse.parse_qs (ref.query,true)
#print ref
#print Get_q (ref)
For k in Get_q (ref):
If k in Ref_qs:
Print ref.netloc+ ":::" +ref_qs[k][0]
Reader.close ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.