-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_chrome_history.py
38 lines (31 loc) · 1.18 KB
/
get_chrome_history.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Modified version of http://sumtxt.wordpress.com/2011/07/02/chrome-browser-history-in-r/
"""
import sqlite3
import codecs
import re
import os
pattern = "(((http)|(https))(www.))"
#Convert chrome webkit time to unix epoch
SQL_STATEMENT = 'SELECT id, datetime((last_visit_time/1000000)-11644473600, \'unixepoch\', \'localtime\'), title, typed_Count, url, visit_count FROM urls WHERE (((last_visit_time/1000000) - 11644473600) > ( SELECT strftime(\'%s\',\'now\') - 108000));'
storage = codecs.open('out.csv', 'w', 'utf-8')
paths = "~/.config/google-chrome/Default/History"
"""
This function queries the sqlite database in which chrome stores history and
returns a csv file
"""
def get_history():
path = os.path.expanduser(paths)
c = sqlite3.connect(path)
#Execute query and loop through result set
for row in c.execute(SQL_STATEMENT):
url = re.search(pattern, str(row[4]))
try:
urlc = url.group(0)
except:
urlc = "ERROR"
if len(urlc) > 120:
continue
#write to csv
storage.write(str(row[0]) + "," + str(row[1]) + "," + '\"' + str(
row[2]) + '\"' + "," + str(row[3]) + "," + row[4] + "\n")