Get Browser History(Chrome & Firefox) using Python in Ubuntu 16.04

Manivannan Murugavel
2 min readFeb 20, 2019

This tutorial expalin how to get the chrome and firefox history from ubuntu 16.04 using python.

The Chrome and Firefox history data stored in sqlite database. So sqlite python package need to extract the data from browser history.

Topics:

  1. Get Chrome History
  2. Get Firefox History

Chrome History:

The Chrome browser all details stored in .config folder and the history details in Default folder.

Open Terminal in ubuntu and run the below command for know more details about chrome browser.

manivannan@manivannan-whirldatascience:~$ cd $HOME/.config/google-chrome/

Note: If you want see the chrome browser history, please close browser. Because the sqlite db is locked.

Code:

import os
import sqlite3
con = sqlite3.connect('/home/manivannan/.config/google-chrome/Default/History')c = con.cursor()
c.execute("select url, title, visit_count, last_visit_time from urls") #Change this to your prefered query
results = c.fetchall()
for r in results:
print(r)

Firefox History:

The Firefox browser all details stored in .mozilla/firefox folder. List out the all files from firefox. Choose the history file which is endwith .default.

manivannan@manivannan-whirldatascience:~$ cd .mozilla/firefox
manivannan@manivannan-whirldatascience:~/.mozilla/firefox$ ls
0mttxac9.default Crash Reports Pending Pings profiles.ini
manivannan@manivannan-whirldatascience:~/.mozilla/firefox$ ls 0mttxac9.default/

Note: Same as chrome. once you close the browser and see the history

Code:

import os
import sqlite3
data_path = os.path.expanduser('~')+"/.mozilla/firefox/0mttxac9.default"
files = os.listdir(data_path)
history_db = os.path.join(data_path, 'places.sqlite')
c = sqlite3.connect(history_db)
cursor = c.cursor()
select_statement = "select moz_places.url, moz_places.visit_count from moz_places;"
cursor.execute(select_statement)
results = cursor.fetchall()
for url, count in results:
print(url)

--

--

Manivannan Murugavel
Manivannan Murugavel

Written by Manivannan Murugavel

Artificial Intelligence and Data Science

Responses (1)