[英]Scraping Yelp for Motel Reviews
EDIT: I have code now using the Yelp API, but it only gives me three reviews per motel. 编辑:我现在使用Yelp API编写代码,但每个汽车旅馆只给我三个评论。 How can I adjust my code to provide more reviews?
如何调整代码以提供更多评论? I'm more interested in having a larger sample size of reviews than of motels.
与汽车旅馆相比,我对拥有更大的评论样本量更感兴趣。
Code below: 代码如下:
import requests
import json
api_key = 'my api key is here'
headers = {'Authorization': 'Bearer %s' % api_key}
url = 'https://api.yelp.com/v3/businesses/search'
params = {'term':'motel','location':'my city is here'}
req = requests.get(url, params=params, headers=headers)
parsed = json.loads(req.text)
businesses = parsed["businesses"]
for business in businesses:
print("Name:", business["name"])
print("Rating:", business["rating"])
print("Address:", " ".join(business["location"]["display_address"]))
print("Phone:", business["phone"])
print("\n")
id = business["id"]
url="https://api.yelp.com/v3/businesses/" + id + "/reviews"
req = requests.get(url, headers=headers)
parsed = json.loads(req.text)
reviews = parsed["reviews"]
print("--- Reviews ---")
for review in reviews:
print("User:", review["user"]["name"], "Rating:", review["rating"], "Review:", review["text"], "\n")
I am very new to coding and am having trouble finding code that I can make work for my task at hand. 我对编码非常陌生,很难找到可以为自己的任务工作的代码。 I need to scrape Yelp reviews (or TripAdvisor if that is easier) from multiple different motels.
我需要从多个不同的汽车旅馆中获取Yelp的评论(如果比较简单,则可以使用TripAdvisor)。 I would be looking at a geographic area (my current city) and scraping the reviews from the motels in that area.
我将查看一个地理区域(我当前所在的城市),并从该区域的汽车旅馆中收集评论。 Then, I need to search the reviews for certain key terms.
然后,我需要在评论中搜索某些关键术语。 Any recommendations?
有什么建议吗?
I would suggest using the requests library in Python and sending API requests using Yelp's API! 我建议在Python中使用请求库,并使用Yelp的API发送API请求!
https://www.yelp.com/developers/documentation/v3 https://www.yelp.com/developers/documentation/v3
If memory serves, you'll need to sign up to get an API key from Yelp. 如果有足够的内存,则需要注册以从Yelp获取API密钥。 Whole process is rather quick.
整个过程相当快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.