Turn Your Chrome History into Insightful Visual Reports with Python & Dash

This article explains how to build a Python‑based Dash web application that parses Chrome's SQLite history file, extracts URLs, visit counts and timestamps, and visualizes the data with Plotly charts, covering project structure, key functions, file handling, and deployment steps.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Turn Your Chrome History into Insightful Visual Reports with Python & Dash

Introduction

This tool lets you analyze your Chrome browsing history, showing visited domains, URLs, and activity statistics in an interactive web dashboard. It runs on any Chrome‑based browser and displays the top ten domains, visit counts, total time spent, and various charts.

Directory Structure

Code
├─ app_callback.py          # Callback functions for backend logic
├─ app_configuration.py     # Web server configuration
├─ app_layout.py            # Front‑end page layout (HTML/CSS)
├─ app_plot.py              # Plotly chart generation
├─ app.py                   # Server entry point
├─ assets
│  ├─ css
│  │  ├─ custum-styles_phyloapp.css
│  │  └─ stylesheet.css
│  ├─ image                 # Logo and icons
│  └─ static                # Help pages (help.html, help.md)
├─ history_data.py          # Parse Chrome history SQLite file
└─ requirement.txt          # Python dependencies

Core Functions

1. Parsing the History File

The history_data.py module connects to the SQLite database, runs a SELECT query joining the urls and visits tables, sorts the results, and returns a list of tuples containing URL, title, timestamps, visit counts, and durations.

# Query SQLite database
def query_sqlite_db(history_db, query):
    conn = sqlite3.connect(history_db)
    cursor = conn.cursor()
    cursor.execute(query)
    results = cursor.fetchall()
    cursor.close()
    conn.close()
    return results

# Get sorted history data
def get_history_data(history_file_path):
    try:
        select_statement = "SELECT urls.id, urls.url, urls.title, urls.last_visit_time, urls.visit_count, visits.visit_time, visits.from_visit, visits.transition, visits.visit_duration FROM urls, visits WHERE urls.id = visits.url;"
        result = query_sqlite_db(history_file_path, select_statement)
        result_sort = sorted(result, key=lambda x: (x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8]))
        return result_sort
    except:
        return 'error'

2. Generating Charts

The app_plot.py module uses Plotly to create bar charts, scatter plots, and other visualizations based on the processed history data.

# Plot bar chart of website visit counts
def plot_bar_website_count_rank(value, history_data):
    dict_data = {}
    for data in history_data:
        url = data[1]
        key = url_simplification(url)
        if key in dict_data:
            dict_data[key] += 1
        else:
            dict_data[key] = 0
    k = convert_to_number(value)
    top_10_dict = get_top_k_from_dict(dict_data, k)
    figure = go.Figure(
        data=[go.Bar(x=list(top_10_dict.keys()), y=list(top_10_dict.values()), marker=dict(color='rgb(55, 83, 109)'))],
        layout=go.Layout(showlegend=False, xaxis=dict(title='Website'), yaxis=dict(title='Count'))
    )
    return figure

3. Dash Callbacks

Callbacks in app_callback.py connect user inputs (e.g., number of top sites) to chart updates. The upload callback decodes a base64‑encoded History file, saves it locally, parses it with history_data.py, and stores the result for the front‑end.

# Update chart based on input value and stored history data
@app.callback(Output('graph_website_count_rank', 'figure'),
              [Input('input_website_count_rank', 'value'),
               Input('store_memory_history_data', 'data')])
def update(value, store_memory_history_data):
    if store_memory_history_data:
        history_data = store_memory_history_data['history_data']
        figure = plot_bar_website_count_rank(value, history_data)
        return figure
    else:
        raise dash.exceptions.PreventUpdate("cancel the callback")

Obtaining the Chrome History File

Depending on the operating system, copy the History SQLite file to a convenient location:

Windows:

C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default\History

Windows XP:

C:\Documents and Settings\%USERNAME%\Local Settings\Application Data\Google\Chrome\User Data\Default\History

macOS: ~/Library/Application Support/Google/Chrome/Default/History Linux/Unix: ~/.config/google-chrome/Default/History Copy the file to the desktop (or any folder) before uploading it through the web interface.

Running the Application

# Navigate to project directory
cd <project_folder>
# Reinstall dependencies
pip uninstall -y -r requirement.txt
pip install -r requirement.txt
# Start the server
python app.py
# Open http://localhost:8090 in a browser

Additional Notes

The full source code is available on GitHub at https://github.com/shengqiangzhang/examples-of-web-crawlers . The project is continuously updated.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonSQLiteDASHweb appChrome History
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.