-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirefoxHistoryScapper.py
44 lines (33 loc) · 1.26 KB
/
FirefoxHistoryScapper.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
39
40
41
42
43
44
import sqlite3
import pandas as pd
# Path to the places.sqlite file in the Firefox profile
places_db = 'C:/Users/user/AppData/Roaming/Mozilla/Firefox/Profiles/012345678901234567890123456789012/places.sqlite'
# Connect to the SQLite database
conn = sqlite3.connect(places_db)
conn.text_factory = lambda b: b.decode(errors='ignore') # Decode bytes with errors ignored
cursor = conn.cursor()
# Query to extract history data
query = """
SELECT
moz_places.url,
moz_places.title,
moz_historyvisits.visit_date / 1000000 AS visit_date, -- Firefox stores timestamps in microseconds
datetime(moz_historyvisits.visit_date/1000000, 'unixepoch', 'localtime') AS visit_datetime
FROM
moz_places
JOIN
moz_historyvisits ON moz_places.id = moz_historyvisits.place_id
ORDER BY
visit_date DESC
"""
# Execute the query and fetch data
cursor.execute(query)
rows = cursor.fetchall()
# Close the database connection
conn.close()
# Convert the data into a pandas DataFrame
df = pd.DataFrame(rows, columns=['URL', 'Title', 'Visit Timestamp', 'Visit Datetime'])
# Save the DataFrame to a CSV file (UTF-8 format)
df.to_csv('firefox_history_backup.csv', index=False, encoding='utf-8-sig')
#save to the same folder that the code is running
print("Backup completed successfully.")