Sorry I'm a noobie with Python, I apologize that this question is extremely vague... Essentially, what I want to do is get a list of all bars in certain cities (ie Toronto, San Francisco, etc). I have used this https://github.com/Yelp/yelp-api/tree/master/v2/python but this only grabs the top result from the queried list. How would I manipulate this to grab all results?
Take a look at the code that actually runs the search for you
businesses = response.get('businesses')
if not businesses:
print u'No businesses for {0} in {1} found.'.format(term, location)
return
business_id = businesses[0]['id']
It's the last line that's limiting the result to just the first ( [0]
) result. If you loop over the entire businesses
variable you will get the full list instead. You will either need to modify the code where it's installed on your machine or just download that file and modify it in-place. For Python scripts like that, the lines
if __name__ == '__main__':
main()
are what runs when you run python sample.py
at the command line. Modify the function main()
or the functions it calls to modify the behavior you get.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.