Skip to content

Instantly share code, notes, and snippets.

@ghutchis
Created May 11, 2017 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghutchis/f7362256064e3ad82aaf583511fca503 to your computer and use it in GitHub Desktop.
Save ghutchis/f7362256064e3ad82aaf583511fca503 to your computer and use it in GitHub Desktop.
Parse Safari Reading List using Python
import os
import plistlib
import requests
INPUT_FILE = os.path.join(os.environ['HOME'], 'Library/Safari/Bookmarks.plist')
OUTPUT_FILE = 'readinglist.txt'
# Load and parse the Bookmarks file
with open(INPUT_FILE, 'rb') as plist_file:
plist = plistlib.load(plist_file)
# Look for the child node which contains the Reading List data.
# There should only be one Reading List item
children = plist['Children']
for child in children:
if child.get('Title', None) == 'com.apple.ReadingList':
reading_list = child
# Extract the bookmarks
bookmarks = reading_list['Children']
for bookmark in bookmarks:
url = bookmark['URLString']
try:
text = bookmark['ReadingList']['PreviewText']
except:
text = ""
title = bookmark['URIDictionary']['title']
ret = requests.head(url)
print("%s, %d, %s, %s" % (url, ret.status_code, title, text))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment