读取谷歌浏览器history 文件

Chrome上网记录提取小试——History - 知乎 (zhihu.com)

Chrome历史记录分析 - 巨兽~墨菲特 - 博客园 (cnblogs.com)

.这个文件是sqllite格式

python 读取sqllite

 1 # -*- coding:utf8 -*-
 2 
 3 '''
 4 Author:Wang Yanlong
 5 Date: 2017-08-16
 6 
 7 All rights reserved.
 8 Distributed under the BSD license.
 9 
10 References:
11     https://docs.python.org/2/library/sqlite3.html  (English)
12     http://www.runoob.com/sqlite/sqlite-python.html (Chinese)
13 '''
14 
15 import sqlite3 as db
16 
17 # 从SQLite文件中读取数据
18 def readFronSqllite(db_path,exectCmd):
19     conn = db.connect(db_path)  # 该 API 打开一个到 SQLite 数据库文件 database 的链接,如果数据库成功打开,则返回一个连接对象
20     cursor=conn.cursor()        # 该例程创建一个 cursor,将在 Python 数据库编程中用到。
21     conn.row_factory=db.Row     # 可访问列信息
22     cursor.execute(exectCmd)    #该例程执行一个 SQL 语句
23     rows=cursor.fetchall()      #该例程获取查询结果集中所有(剩余)的行,返回一个列表。当没有可用的行时,则返回一个空的列表。
24     return rows
25     #print(rows[0][2]) # 选择某一列数据
26 
27 # 解析ARPA 单帧信息
28 def readfromAppaFrame(ARPAFrame):
29     subARPA=ARPAFrame.split(',')
30     print(subARPA)
31 
32 if __name__=="__main__":
33     rows=readFronSqllite('E://ARPA.db',"select ARPA from ARPAInfo")
34     readLines=10010
35     lineIndex=10000
36     while lineIndex<readLines:
37         row=rows[lineIndex] # 获取某一行的数据,类型是tuple
38         content="".join(row) #tuple转字符串
39         readfromAppaFrame(content) # 解析ARPA数据
40         lineIndex+=1

 ————————————更新——————————————————————————

读取代码,同时包含转换时间戳

 1 import sqlite3 as db
 2 import time
 3 # 从SQLite文件中读取数据
 4 def readFronSqllite(db_path,exectCmd):
 5     conn = db.connect(db_path)  # 该 API 打开一个到 SQLite 数据库文件 database 的链接,如果数据库成功打开,则返回一个连接对象
 6     cursor=conn.cursor()        # 该例程创建一个 cursor,将在 Python 数据库编程中用到。
 7     conn.row_factory=db.Row     # 可访问列信息
 8     cursor.execute(exectCmd)    #该例程执行一个 SQL 语句
 9     rows=cursor.fetchall()      #该例程获取查询结果集中所有(剩余)的行,返回一个列表。当没有可用的行时,则返回一个空的列表。
10     return rows
11     #print(rows[0][2]) # 选择某一列数据
12 
13 # 解析ARPA 单帧信息
14 def readfromAppaFrame(ARPAFrame):
15     subARPA=ARPAFrame.split(',')
16     print(subARPA)
17 
18 if __name__=="__main__":
19     rows=readFronSqllite('./data/History.db',"select url,title,last_visit_time from urls  ")
20     print(rows[0])
21     visite_time=rows[0][2]
22     true_time=visite_time/1000000-11644473600
23     time_normal = time.gmtime(true_time)  # 转换为普通时间格式(时间数组)
24     dt = time.strftime("%Y-%m-%d %H:%M:%S", time_normal)  # 格式化为需要的格式
25     print(f"根据Unix时间戳得到的普通时间:{dt}")
26     # readfromAppaFrame("".join(rows[1]))
27     # print(len(rows))
28     # while lineIndex<readLines:
29     #     row=rows[lineIndex] # 获取某一行的数据,类型是tuple
30     #     content="".join(row) #tuple转字符串
31     #     readfromAppaFrame(content) # 解析ARPA数据
32     #     lineIndex+=1
原文地址:https://www.cnblogs.com/smartisn/p/15776694.html