Skip to main content

Load / dump Chrome bookmark files

Project description

Install

$ pip install zbookmarks

Usage

A simple python package for loading / dumping Chrome HTML bookmarks. Born out of necessity to fix my own bookmarks.

import zbookmarks

# Load
with open("chrome_bookmarks.html", "r") as f:
    bookmarks = zbookmarks.load_chrome(f.read())

# Print
print(bookmarks)

# Dump
with open("output.html", "w") as f:
    zbookmarks.dump_chrome(bookmarks, f)

How it works

I made this package by examining my own Chrome bookmark files and extrapolating. The general rules are:

  • dl denotes a list of bookmark items and folders.
  • dt denotes either a bookmark item or folder:
    • If it's a bookmark item, dt has a single a tag child, which gives the bookmark attributes (href, title, etc.).
    • If it's a bookmark folder, dt has 3 children:
      • A h3 tag containing the folder attributes (title, etc.)
      • A dl tag containing the folder's contents.
      • A useless p child tag.

I found it easier to come up with these rules after visualizing the DOM tree of a Chrome bookmarks file:

Visualize DOM tree of bookmarks file

You can try it out on your own bookmark file by running:

# You need to install graphviz (dot) in order to run the script
$ sudo apt-get install -y graphviz
$ poetry install
$ python3 scripts/visualize_dom.py <my_bookmarks_file.html>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zbookmarks-1.3.tar.gz (7.0 kB view hashes)

Uploaded source

Built Distribution

zbookmarks-1.3-py3-none-any.whl (7.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page