Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Export Google Maps starred locations
# -*- coding: utf-8 -*-
Go to Google Bookmarks:
On the bottom left, click "Export bookmarks":
After downloading the html file, run this script on it to generate a KML.
from lxml.html import document_fromstring
import simplekml
from urllib2 import urlopen
import re
import time
filename = r'GoogleBookmarks.html'
with open(filename) as bookmarks_file:
data =
kml = simplekml.Kml()
# Hacky and doesn't work for all of the stars:
lat_re = re.compile('markers:[^\]]*latlng[^}]*lat:([^,]*)')
lon_re = re.compile('markers:[^\]]*latlng[^}]*lng:([^}]*)')
coords_in_url = re.compile('\?q=(-?\d{,3}\.\d*),\s*(-?\d{,3}\.\d*)')
doc = document_fromstring(data)
for element, attribute, url, pos in doc.body.iterlinks():
if '' in url:
description = element.text or ''
print description.encode('UTF8')
print u"URL: {0}".format(url)
# Coordinates are in URL itself
latitude =[0]
longitude =[1]
# Load map and find coordinates in source of page
sock = urlopen(url.replace(' ','+').encode('UTF8'))
except Exception, e:
print 'Connection problem:'
print repr(e)
print 'Waiting 2 minutes and trying again'
sock = urlopen(url.replace(' ','+').encode('UTF8'))
content =
time.sleep(3) # Don't annoy server
latitude = lat_re.findall(content)[0]
longitude = lon_re.findall(content)[0]
except IndexError:
print '[Coordinates not found]'
print latitude, longitude
coords=[(float(longitude), float(latitude))])
except ValueError:
print '[Invalid coordinates]'

I'm using (part of) this at . I am assuming I can, since there's no LICENSE information for this gist, but I wouldn't mind getting explicit permission.


You have explicit permission! :)


How do you run the html file in KML? I did get all the names of my bookmarks (thank you for that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.