#!usr/bin/env python #-*- coding:utf-8 _*- """ @author:lenovo @file: 獲取瀏覽器歷史記錄.py @time: 2019/11/04 """ import os import sqlite3 import shutil import datetime import pandas as pd ''' last_visit_time => 起始值:1601年1月1日0時0分0秒 11644473600 print(13216100327877073/10**6-11644473600) ''' dbpath = r"C:\Users\lenovo\AppData\Local\Google\Chrome\User Data\Default\history" '''這裏我複製一個出來從新命名''' historydb = shutil.copy(dbpath,r"C:\\Users\\lenovo\AppData\\Local\\Google\\Chrome\\User Data\\Default\\history1") #查詢數據庫類容 conn = sqlite3.connect(historydb) cursor = conn.cursor() sql = "select url,visit_count,last_visit_time from urls " cursor.execute(sql) results = cursor.fetchall() #print(type(results),results) ur,vi,tim = [],[],[] for i in results: ur.append(i[0]) visit_count = i[1] vi.append(visit_count) un_time = round(i[2]/10**6-11644473600) times = datetime.datetime.fromtimestamp(un_time) tim.append(times) # 建立數據表 house = pd.DataFrame({'網址': ur, '瀏覽次數': vi, '瀏覽時間': tim}) # 查看數據表的內容 house.head() house.to_csv('本地谷歌瀏覽記錄.csv', encoding='gbk')
最後獲得結果:python