简体   繁体   English

如何从 Yelp API 请求中获得超过 3 条评论

[英]How to get more than 3 reviews from Yelp API request

I would like to retrieve reviews for a clinic in New York via the Yelp API.我想通过 Yelp API 检索纽约一家诊所的评论。 However, the API only seems to only return the first three reviews.但是,API 似乎只返回前三个评论。

My code我的代码

# Finding reviews for a particular clinic
import http.client
import json
import urllib.parse

api_key= 'MY API KEY'

API_HOST = 'https://api.yelp.com/reviews'
SEARCH_PATH = '/v3/businesses/search'
BUSINESS_PATH = '/v3/businesses/'  
# Business ID will come after slash.


headers = {
'Authorization': 'Bearer %s' % api_key,
}

#need the following parameters (type dict) 
params = {'name':'MinuteClinic', 'address1':'241 West 57th St', 'city':'New York', 'state':'NY', 'country':'US'}


param_string = urllib.parse.urlencode(params)
conn = http.client.HTTPSConnection("api.yelp.com")
conn.request("GET", "/v3/businesses/matches/best?"+param_string, headers=headers)

res = conn.getresponse()
data = res.read()
data = json.loads(data.decode("utf-8"))
print(data)


b_id = data['businesses'][0]['id']

r_url = "/v3/businesses/" + b_id + "/reviews"    #review request URL creation based on business ID
conn.request("GET",r_url,headers=headers)
rev_res = conn.getresponse()     #response and read functions needed else error(?)
rev_data = rev_res.read()
yelp_reviews = json.loads(rev_data.decode("utf-8"))


print(yelp_reviews)
print(len(yelp_reviews))

Is there a way to get all the reviews?有没有办法获得所有评论? Thank you so much.太感谢了。

As you may have seen on the Yelp API documentation , there is currently no way to retrieve more than three reviews for a single business with the Business Reviews endpoint ( /businesses/{id}/reviews ) that you are using.正如您可能在Yelp API 文档中看到的那样,目前无法使用您正在使用的业务评论端点 ( /businesses/{id}/reviews ) 为单个企业检索三个以上的评论。

The only accepted parameter for the Business Reviews endpoint is locale . Business Review 端点唯一接受的参数是locale

In addition, the first sentence of the documentation for that endpoint is此外,该端点的文档的第一句是

This endpoint returns up to three review excerpts for a given business ordered by Yelp's default sort order .此端点最多返回三个按Yelp 的默认排序顺序排序的给定业务的评论摘录。

So, at this time, it seems that Yelp only exposes via their API at most three reviews per business.因此,目前,Yelp 似乎只通过他们的 API 公开每个企业最多三个评论。 Consider submitting a feature request to the GitHub repository for the Yelp API .考虑向Yelp API 的 GitHub 存储库提交功能请求。

I hate Yelp, I also hate that Google follows suite and also caps the amount of reviews returned.我讨厌 Yelp,我也讨厌 Google 遵循套件并限制返回的评论数量。 The reviews are public, it's retarded they aren't willing to give programmatic access to get all of them;评论是公开的,他们不愿意让程序化访问来获得所有评论,这是迟钝的; and they wonder why devs have to create workarounds to bypass these limitations..他们想知道为什么开发人员必须创建解决方法来绕过这些限制。

Anywho;任何人; I created a temp API key for one of my APIs;我为我的一个 API 创建了一个临时 API 密钥; this one will fetch all the reviews you need from any Yelp profile;这个将从任何 Yelp 个人资料中获取您需要的所有评论;

Example call:示例调用:

http://api.reviewsmaker.com/yelp/?url=https://www.yelp.com/biz/chicha-brooklyn&api_key=4b3d3d92-27f4-4eaa-bb8b-281cb8aa3860 http://api.reviewsmaker.com/yelp/?url=https://www.yelp.com/biz/chicha-brooklyn&api_key=4b3d3d92-27f4-4eaa-bb8b-281cb8aa3860

Parameters:参数:

url - full URL of the yelp business page you need to get the reviews for (required) api_key - use the one in the above link, I provisioned it to expire (keep that in mind) rating - you can specify &rating=5 to only pull 5 star reviews, or &rating=2 to only pull 2 star reviews, etc; url - 获取(必需)api_key 评论所需的 yelp 业务页面的完整 URL - 使用上面链接中的那个,我将其设置为过期(记住这一点)评级 - 您可以指定 &rating=5 仅拉 5 星评论,或 &rating=2 只拉 2 星评论等; this is optional, leaving it blank will return all the reviews这是可选的,将其留空将返回所有评论

Go ahead and grab your clinic's stuff :)去拿你诊所的东西:)

Yelp's Fusion API allows users to search for up to 1000 business listings for a keyword, but when it comes to reviews Yelp is not so generous. Yelp 的Fusion API允许用户为一个关键字搜索多达 1000 个企业列表,但在评论方面,Yelp 并不那么慷慨。

However, getting access to their API is next to impossible.然而,访问他们的 API 几乎是不可能的。 I know many people who applied with no success.我认识很多人申请都没有成功。

The only remaining option is to scrape the reviews from Yelp.唯一剩下的选择是从 Yelp 上抓取评论。 While Yelp may claim that they do not "allow" any scraping of their data, they cannot enforce this as scraping of public data remains legal.虽然 Yelp 可能声称他们不会“允许”对其数据进行任何抓取,但他们无法强制执行,因为抓取公共数据仍然是合法的。

The following technologies can be used to write a crawler for Yelp reviews:以下技术可用于为 Yelp 评论编写爬虫:

If you don't have time and don't mind spending a few bucks.如果你没有时间也不介意花几块钱。 I have also built a service that scrapes Yelp reviews for you and returns them as an API response for any listing on Yelp.我还构建了一项服务,可以为您抓取 Yelp 评论并将其作为 API 响应返回给 Yelp 上的任何列表。

It is called Yelp Reviews API and can be used to scrape up to 10,000 reviews for free.它被称为Yelp 评论 API ,可用于免费抓取多达 10,000 条评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM