python统计最近几天访问的网站次数

数据是从chrome中的History分析出来的,它用的是sqlite数据库,python有接口

import sqlite3
import thread
import time
import datetime
import re
def getHistoryDB():
    path=‘C:\Users\Administrator\AppData\Local\Google\Chrome\User Data\Default\History‘
    db=sqlite3.connect(path)#将path换自己电脑History的路径
    cu=db.cursor()
    cu.execute("select url,title,(substr(last_visit_time,1,11)-11644473600) from urls")
    result=cu.fetchall()
    cu.close()
    db.close()
    ‘‘‘
    print ‘length:‘+str(len(result))
   # print getTime(result[len(result)-1][2])
    
    #print result[len(result)-1][2]
    
    for x in range(10):
        print ‘---------------‘
        print getWebsite(result[x][0])
        print result[x][1]
        print getTime(result[x][2])
        #print getTime(result[x][5])
        ‘‘‘
    return result
        
def getWebsite(result):
    AllWebsite={}
    for x in result:
        #处理url
        url=getUrl(x[0])
        #print url
        
        website=url.split(‘.‘)
        #print website
        if len(website)<=1:
            key=‘others‘
        else:
            key=url
        #如果为空
        if key in AllWebsite:
            AllWebsite[key]+=1
        else:
            AllWebsite[key]=1       
    return AllWebsite

def displayWebsite():
    result=getHistoryDB()
    AllWebsite=getWebsite(result)
    for x in AllWebsite:
        print x,AllWebsite[x]
        
 #从url中提起到关键信息,如http://www.baidu.com/xxxxxxx,得到www.baidu.com       
def getUrl(urls):
    reg=re.compile(‘//(.*?)/‘)
    url=reg.findall(urls)
    #print url
    #print len(url)
    if len(url)>0:
        return url[0]
    else:
        return ‘nothing‘
    
#获得访问时间的,没有用到
def getTime(vtime):
    #print vtime
    #vtime=format(float(vtime)/10000000,‘.3f‘)   
    #print vtime
    return time.strftime(‘%Y-%m-%d %H:%M:%S‘,time.localtime(float(vtime)))
    
if __name__==‘__main__‘:
    displayWebsite()
    #getHistoryDB()

python统计最近几天访问的网站次数

去看看你最近常浏览的网站吧,是否有什么有趣的发现

python统计最近几天访问的网站次数,布布扣,bubuko.com

python统计最近几天访问的网站次数

上一篇:论文阅读 Adaptive Consistency Regularization for Semi-Supervised Transfer Learning


下一篇:Java并发编程之线程管理(基本线程同步5)