我试图创建一个函数来过滤从GooglePlacesAPI提取的json数据。如果名称包含字符串“Body Shop”,并且类型为['car_repair'、'point_of_interest'、'Establish'],我希望它返回企业名称和类型值,否则我希望它拒绝结果。这是到目前为止我的代码。我试了又试,但似乎找不到一种方法来存储某些条件以使搜索更容易
import googlemaps
import pprint
import time
import urllib.request
API_KEY = 'YOUR_API_KEY'
lat, lng = 40.35003, -111.95206
#define our Client
gmaps = googlemaps.Client(key = API_KEY)
#Define our Search
places_result = gmaps.places_nearby(location= "40.35003,-111.95206", radius= 40000,open_now= False,type= ['car_repair','point_of_interest','establishment'])
#pprint.pprint(places_result['results'])
time.sleep(3)
places_result_2 = gmaps.places_nearby(page_token =
places_result['next_page_token'])
pprint.pprint(places_result_2['results'])
places_result_2 = gmaps.places_nearby(page_token =
places_result['next_page_token'])
types = place_details['result']['types']
name = place_details['result']['name']
def match(types,name):
for val in types:
'car_repair','point_of_interest','establishment' in val and "Body Shop" in name
print(name,types)
试试这个:
相关问题 更多 >
编程相关推荐