Skip to content

Instantly share code, notes, and snippets.

@jayrambhia
Created January 27, 2012 19:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jayrambhia/1690395 to your computer and use it in GitHub Desktop.
Save jayrambhia/1690395 to your computer and use it in GitHub Desktop.
Extract bookmarks (from html file) from the browser
"""
@author: jay
"""
from BeautifulSoup import BeautifulSoup
import gdbm
import pickle
import time
def main():
f = open('bookmarks.html','r')
soup = BeautifulSoup(f.read())
f.close()
dt=[]
for d in soup.findAll('dt'):
dt.append(d)
f = gdbm.open('bookmark','c')
for i in range(len(dt)):
if dt[i].contents[0].has_key('href') and dt[i].contents[0].has_key('add_date'):
uri = dt[i].contents[0]['href']
title = dt[i].contents[0].contents[0]
add_date = time.ctime(int(dt[i].contents[0]['add_date']))
last_modified = time.ctime(int(dt[i].contents[0]['last_modified']))
f[uri] = pickle.dumps((str(title), add_date, last_modified))
f.close()
if __name__ == '__main__':
main()
@jayrambhia
Copy link
Author

Go to Bookmarks in your browser. Open Show All Bookmarks. Import and Backup > Export Bookmark to HTML > Save the file and feed it to the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment