SMTH
SMTH

Reputation: 95

Unable to produce the value of lat and lng using any state

I've created a script using requests module to get the name of different brokers from a webpage. This is the option that I chose to produce results. Althought the following script can parse the names out of that populated results from that site, I can't figure out how I can produce the value of lat and lng that I've used in params.

As I wish to parse names from few states, it is necessary that I use the value of lat and lng programmatically. Currently they are hardcoded.

I've tried with:

import requests
from pprint import pprint

link = 'https://www.ibba.org/wp-json/brokers/geo'
params = {
    'lat': '40.3607',
    'lng': '-74.3693',
    'miles': '250',
    'specialties': '',
    'cbi': ''
}
with requests.Session() as s:
    s.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
    res = s.get(link,params=params)
    for item in res.json()['features']:
        print(item['geometry']['properties']['name'])

How can I produce the value of lat and lng using any state required to be used within params?

Upvotes: 1

Views: 86

Answers (1)

Jack Fleeting
Jack Fleeting

Reputation: 24940

The real question you have has to do with finding a source for lat/lon coordinates, given a zip code. It's not as trivial as it should be, but fortunately the pgeocode library can handle the task in python.

Upvotes: 2

Related Questions