Skip to content

Instantly share code, notes, and snippets.

@cgimenes
Created September 3, 2024 22:36
Show Gist options
  • Save cgimenes/08a38c15cbfcd5a9cf240ad72d63027a to your computer and use it in GitHub Desktop.
Save cgimenes/08a38c15cbfcd5a9cf240ad72d63027a to your computer and use it in GitHub Desktop.
Script to export Arc Browser bookmarks
import json
file_path = '/Users/<username>/Library/Application Support/Arc/StorableSidebar.json'
lists = {}
tabs = []
with open(file_path, 'r') as f:
parsed_json = json.load(f)
items = parsed_json['sidebar']['containers'][1]['items']
for item in items:
if isinstance(item, str):
continue
if 'list' in item["data"]:
lists[item['id']] = {
'title': item['title'],
'type': 'list',
'items': {},
}
if 'tabGroup' in item["data"]:
lists[item['id']] = {
'title': item['data']['tabGroup']['title'],
'type': 'tabGroup',
'items': {},
}
if 'itemContainer' in item["data"]:
lists[item['id']] = {
'title': 'Favourites, Pinned Tabs and Open Tabs (outside groups)',
'type': 'itemContainer',
'items': {},
}
for item in items:
if isinstance(item, str):
continue
if 'tab' in item["data"]:
lists[item["parentID"]]['items'][item['id']] = {
"url": item["data"]['tab']['savedURL'],
"title": item["data"]['tab']['savedTitle'],
}
html = '<!DOCTYPE NETSCAPE-Bookmark-file-1>\n'
html += '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">\n'
html += '<TITLE>Bookmarks</TITLE>\n'
html += '<H1>Bookmarks</H1>\n'
html += '<DL><p>\n'
for list_id, folder in lists.items():
html += f' <DT><H3>{folder['title']}</H3>\n'
html += ' <DL><p>\n'
for tab_id, item in folder['items'].items():
html += f' <DT><A HREF="{item["url"]}">{item["title"]}</A>\n'
html += ' </DL><p>\n'
html += '</DL><p>\n\n'
with open('dump.html', 'w') as f:
f.write(html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment