Created
May 11, 2017 02:00
-
-
Save ghutchis/f7362256064e3ad82aaf583511fca503 to your computer and use it in GitHub Desktop.
Parse Safari Reading List using Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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