Skip to content

Instantly share code, notes, and snippets.

@ByteSizedMarius
Last active May 24, 2024 01:32
Show Gist options
  • Save ByteSizedMarius/8c9df821ebb69b07f2d82de01e68387d to your computer and use it in GitHub Desktop.
Save ByteSizedMarius/8c9df821ebb69b07f2d82de01e68387d to your computer and use it in GitHub Desktop.
Google Maps: Extract places from shared list
import html
import re
import requests
x: requests.Response = requests.get(PASTE LINK HERE)
txt = x.text.split(r")]}'\n")[2].split("]]\"],")[0] + "]]"
txt = html.unescape(txt)
results = re.findall(r"\[null,null,[0-9]{1,2}\.[0-9]{4,15},[0-9]{1,2}\.[0-9]{4,15}]", txt)
for cord in results:
curr = txt.split(cord)[1].split("\\\"]]")[0]
curr = curr[curr.rindex("\\\"") + 2:]
cords = str(cord).split(",")
lat = cords[2]
lon = cords[3][:-1]
print("Name: " + curr)
print("Coords: " + lat + ", " + lon + "\n")

Edit: This doesn't work for lists > 20 items, because pagination does not work. Please see here

This script allows extracting name and coordinates for gmaps shared lists. It is incredibly unstable and may break anytime. Good luck figuring out why, because the syntax is extremely confusing and basically makes no sense at all. Thanks to google for not providing an api for this after LITERALLY 12 YEARS

How to use this script:

  1. Share a list and open the link in a browser window. It will redirect. The new link will look like this: google.com/maps/@<your coords>/data=....
  2. Take the data-portion and paste it into the following link: https://google.com/maps/@/data=<data>?ucbcb=1
  3. Take this link and paste it into the py-script below.
@Ac2zoom
Copy link

Ac2zoom commented Dec 30, 2022

I don't have the reputation to comment on your StackOverflow answer (thank you so much for writing that), but if it's useful to anyone else, I refined the regex to work for negative and >=100 longitude for extracting the coordinates: /[null,null,-[0-9]{1,2}.[0-9]{4,15},-[0-9]{1,3}.[0-9]{4,15}]

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