你绝对不是百分之百错的@g嫒altobelli!在
让我们举一个为商业X获取评论的例子,X是我最喜欢的旧金山拉塔奎亚餐厅之一。他们的餐厅id(可以在评论页面的url中找到最后一个元素)是la-taqueria-san-francisco-2。在
现在我们的代码是:
你使用请求的想法是正确的,我想你的参数可能有点偏差。最初有一些标题是有帮助的。我补充道:import requests
API_KEY = ""
API_HOST = 'https://api.yelp.com'
BUSINESS_PATH = '/v3/businesses/'
然后我创建了一个函数,它接受业务id并返回基本数据的jsonified结果。看起来像这样:
^{pr2}$
最后,我用我的值调用函数并打印结果:results = get_business('la-taqueria-san-francisco-2')
print(results)
我得到的输出是json,大致如下所示:
{'reviews': [{'id': 'pD3Yvc4QdUCBISy077smYw', 'url': 'https://www.yelp.com/biz/la-taqueria-san-francisco-2?hrid=pD3Yvc4QdUCBISy077smYw&adjust_creative=hEbqN49-q6Ct_cMosX68Zg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_reviews&utm_source=hEbqN49-q6Ct_cMosX68Zg', 'text': 'My second time here.. \nI love the Burito here it has the distinct taste of freshness.. we order super steak burito and boy it did not disappoint! everything...}
这有帮助吗?如果你还有什么问题请告诉我。在