سؤال

أحاول جمع معلومات عن المطعم على موقع Yelp.لدي اسم المطعم، وأستخدم yelpapi.

لقد كتبت ما يلي:

from yelpapi import YelpAPI
yelp_api = YelpAPI(<key>, <secret>, <token>, <token secret>)
search_results = yelp_api.search_query(name = 'Neptune Oyster', location='Boston, MA'),

ولكن انتهى الأمر بقائمة تضم 20 شركة، ولم تكن أي منها هي الشركة الصحيحة.كيف يمكنني تحديد اسم المطعم في استعلام API الخاص بي؟

وأيضًا، كيف يمكنني سحب جميع التقييمات الخاصة بمطعم معين؟

شكرًا!

هل كانت مفيدة؟

المحلول

هل هذا هو المطعم الذي تبحث عنه:

http://www.yelp.com/biz/neptune-oyster-boston?

كل شيء بعد "/" الأخير هو معرف المطعم.

بمجرد حصولك على معرف yelp، ستحتاج إلى استخدام واجهة برمجة تطبيقات الأعمال للحصول على التعليقات

إليك الوثائق الخاصة بواجهة برمجة تطبيقات الأعمال

http://www.yelp.com/developers/documentation/v2/business

سيكون طلبك للحصول على التقييمات كما يلي:

http://api.yelp.com/v2/business/neptune-oyster-boston

وعلى وجه التحديد بالنسبة لـ python yelpapi، يمكن إنشاء الطلب على النحو التالي:

yelp_api.business_api('neptune-oyster-boston')

لقد أعطتني فقط مقتطفًا من المراجعة، وللحصول على المراجعة الكاملة، أعتقد أنه قد يتعين عليك مسح موقع الويب.انظر إلى BeautifulSoup وScrapy.

أخيرًا، للإجابة على سؤالك الأول، حاول الاستبدال name مع term في معلمة البحث الخاصة بك.يمكنك العثور على قائمة بمعلمات البحث الصالحة الأخرى في هذه الصفحة:

http://www.yelp.com/developers/documentation/v2/search_api

من خلال الاستعلام التالي، أعطتني واجهة برمجة التطبيقات العمل المناسب.

yelp_api.search_query(term='neptune oysters', location='boston', limit=1)

حظا سعيدا وتقطيع سعيد!

نصائح أخرى

أسفرت API NELP NELP Fusion (V3) الأحدث عن بعض التغييرات في كيفية استخدام API والمعلومات التي تم إرجاعها.أقل من ذلك هو V2 يمكن الحصول على ملاحظات مكالمة واحدة.يتطلب v3 مكالمتين.فيما يلي كيف تمكنت من الحصول عليها للعمل.قد يختلف الأميال الخاص بك.

giveacodicetagpre.

Specifying the restaurant name using term instead of name seems to work.

from yelpapi import YelpAPI
yelp_api = YelpAPI(key, secret, token, token_secret)
search_results = yelp_api.search_query(term='Neptune Oyster', location='Boston, MA')

>>> for business in search_results['businesses']:
...     print business['name']
... 
Neptune Oyster
Island Creek Oyster Bar
B & G Oysters
Rabia's
Union Oyster House
Pauli's
James Hook & Co
Row 34
Atlantic Fish Company
Mare
The Oceanaire Seafood Room
Alive & Kicking Lobsters
The Daily Catch
Yankee Lobster Fish Market
The Barking Crab
Boston Chowda Co.
Legal Sea Foods
Salty Dog Seafood Grille & Bar
Legal Sea Foods
Legal Sea Foods

According to the documentation, you are limited to 1 excerpt of a review. You can get that using a business query with the id of the business that you got from the search query:

>>> search_results = yelp_api.search_query(limit=1, term='Neptune Oyster', location='Boston, MA')
>>> if search_results['businesses'][0]['name'] == 'Neptune Oyster':
...     business_id = search_results['businesses'][0]['id']
...     business_results = yelp_api.business_query(id=business_id)
...     for review in business_results['reviews']:
...         print review['excerpt']
... 
Price/Food
- Waited almost two hours for this place! I talked to some people that were waiting in line and they were all raving that Neptune is the BEST...
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top