Maverick Maverick -4 years ago 102
Python Question

Python "scraping" maps/images

I want to use Python to scrape snapshots of maps/images of properties. I have the post code for all of the properties I need to get maps/images for, but I am unsure how to use Python to take the postcode, search a website, take a snap shot of the map and then save it.

I had initially thought to use Selenium, but not sure this would be the most efficient way to search the websites?

Only been learning Python a few months so would really appreciate if someone could point me in the right direction!

Answer Source

You could use Google's static maps API like so:

import requests

zoom = '13'
size = '600x300'
maptype = 'roadmap'

scheme = '[Location]&zoom={0}&size={1}&maptype={2}'.format(zoom, size, maptype)
locations = ['Brooklyn+Bridge,New+York,NY', '2550+SW+Hillsboro+Hwy,Hillsboro,OR', 'TX+78016']  # place, address, state+zip

for loc in locations:

    url = scheme.replace('[Location]', loc)
    resp = requests.get(url)

    print('Status code: {0} | {1}'.format(resp.status_code, url))

    if resp.status_code == 200:

        with open('map_image_{0}.png'.format(loc), 'wb') as f:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download