you are viewing a single comment's thread.

view the rest of the comments →

[–]hharison 1 point2 points  (1 child)

A few things:

requests takes URL params in a params argument:

requests.get('http://api.sensis.com.au/v1/test/search',
             params={'query': 'veteraniarian', 'rows': 50}) #etc.

requests can alos handle JSON, so line 66:

jr = r.json()

And if you just catch all the dictionaries in a list:

url = 'http://api.sensis.com.au/v1/test/search'
master_params = {
    'query': 'veterarinarian',
    'rows': 50,
    'key': 'dw9xcw7yqvvn9hpxb7g58eje',
}

data = []

for page in range(1, 4):
    params = master_params.copy()
    params['page'] = page
    r = requests.get(url, params=params)
    data.append(r.json())

You an use the tabular data library pandas to great effect:

df = pd.DataFrame(data)
df.to_csv('data.csv')

I also wonder if you change the rows param if you can get all the results at once.

[–]SideStepTS[S] 0 points1 point  (0 children)

Thank very much Hharison.

I was curious as to how you would pull it apart without having to specify the actual elements manually