June 26, 2014


Alternative of google-map API, making request more than 2500.

I was looking for a free api which can help me to get latitude/longitude on the basis of Postcode.

I tested pygeocoder and other api librearies which can help me, but none of them allowed me to query more than 25,000/day cause everyone is belongs to Google.

So I did an old school coding by using Mechanize and BeautifulSoup.
I used http://services.gisgraphy.com/public/geocoding.html. It's a free, I think they are providing 30,000 requests for demo user, I didn't tested 30,000 requests cause I've 29,000 records to generate lat/long. I don't want to waste my hits for a day. I'll test and update here.

Code is not clean, cause it's a test.

Keep Coding .

import mechanize
from bs4 import BeautifulSoup 

for x in xrange(30000):

    print '----------------- searching ---------------'
    br = mechanize.Browser()
    add = '81100'
    br.form["address"] = add
    for i in range(0, len(br.find_control(type="checkbox").items)):
        br.find_control(type="checkbox").items[i].selected =True
    print 'hitting --- ',x
    response = br.submit()
    soup = BeautifulSoup(response)
    links = soup.find_all('li')
    print '--------- getting list ----------'
    li = soup.find('div', {'class': 'summary'})
    print '---------- looking for latitude and longitude -------------'
    list= []
    children = li.findChildren()
    for child in children:

    print ' found latitude and longitude at point -->  ',x
    latitude = list[0]
    longitude = list[1]
    lat = latitude[9+5:len(latitude)-5].split()
    lng = longitude[9+6:len(longitude)-5].split()
    print str(lat).replace(',','.')
    print str(lng).replace(',','.')

#for f in br.forms():
#    print f

Source Code : https://bitbucket.org/ashish2py/quickhack/

Follow Us @soratemplates