I'm trying to collect restaurant information on yelp. I have the restaurant name, and am using yelpapi.
I typed in the following:
from yelpapi import YelpAPI
yelp_api = YelpAPI(<key>, <secret>, <token>, <token secret>)
search_results = yelp_api.search_query(name = 'Neptune Oyster', location='Boston, MA'),
But ended up with a list of 20 businesses, none of which are the right one. How should I specify restaurant name in my API query?
Also, how would I go about pulling out all of the reviews for a given restaurant?
Thanks!
Is this the restaurant you're looking for:
http://www.yelp.com/biz/neptune-oyster-boston?
Everything after the last '/' is the restaurant's yelp-id.
Once you have the yelp-id you need to use the business api to get reviews
Here's the documentation for the business api
http://www.yelp.com/developers/documentation/v2/business
Your request to get the reviews would be like this:
http://api.yelp.com/v2/business/neptune-oyster-boston
and, specifically for the python yelpapi, the request can be constructed as
yelp_api.business_api('neptune-oyster-boston')
It only gave me a snippet of the review, for the full review, I think you might have to scrape the website. Look into BeautifulSoup and Scrapy.
Finally, to answer your first question, try replacing name
with term
in your search parameter. You can find a list of other valid search parameters on this page:
http://www.yelp.com/developers/documentation/v2/search_api
With the following query,the api gave me the right business.
yelp_api.search_query(term='neptune oysters', location='boston', limit=1)
Good luck and happy scraping!