#!/usr/bin/env python3 import requests import json from bs4 import BeautifulSoup # Stolen from my machine, appears to work; sufficient and necessary to get # around their firewall apparently? UA={ "User-Agent": 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0' } response = requests.get('https://milwaukeeburgercompany.com/', headers=UA) soup = BeautifulSoup(response.text, 'html.parser') location_lis = soup.select('section#locations ul.location-list > li') locations = [] for location_li in location_lis: lon = location_li locations.append({ "type": "Feature", "geometry": { "type": "Point", "coordinates": [float(location_li['data-lng']), float(location_li['data-lat'])], # yes, [lon, lat] since it's [x, y] }, "properties": { 'address': location_li.find('dd', class_="street").text, 'city': location_li.find('dd', class_="city-state-zip").text.split(',')[0], 'state': location_li.find('dd', class_="city-state-zip").text.split(', ')[1].split(' ')[0], 'zip': location_li.find('dd', class_="city-state-zip").text.split(' ')[-1], }, }) geojson = { "type": "FeatureCollection", "features": locations, } print(len(locations), "locations found") with open("data.geojson", "w") as f: f.write(json.dumps(geojson))