Python Google Places Api

时间:2016-08-24 20:24:59

标签: python json google-maps google-places-api

我正在尝试捕捉考文垂的星巴克商店的详细信息,如姓名,位置,地址和谷歌地图网址,但我似乎无法绕过时间表(开放时间)

print place.details 

将为您提供有关JSON格式的所有详细信息,如何仅保留开放时间

Starbucks Coffee
This is the address of the place :  Gulson Road Coventry University, Coventry CV1 2JH, UK
The google map page :  https://maps.google.com/?cid=5279103370560834505
The type of place :  [u'cafe', u'food', u'store', u'point_of_interest', u'establishment']
{u'website': u'http://www.starbucks.co.uk/store/91356/gb/coventry-university-ecb/gulson-road-ecb-engineering-computing-building', u'utc_offset': 60, u'name': u'Starbucks Coffee', u'reference': u'CnRjAAAADvWg02OACGcjnA6lDYaiHaLuZDZkFnL3lGuw_QOw0i4fmmgcaUXXyROMIKW3eZR1tvorm-T6fAG0b815POJV7mSg4MnISitEn_SKGcs5hq5I2DY2CyAiwAFFjDsJkEWrj6NFEjnaF916KuQ-JXfzghIQdSyG6bHTdaMvn-ZZFXLR5hoUFsXDJ9gx-l0Ys5D6BG9IQV1emGU', u'price_level': 2, u'geometry': {u'location': {u'lat': Decimal('52.4055608'), u'lng': Decimal('-1.4997924')}, u'viewport': {u'northeast': {u'lat': Decimal('52.40569205'), u'lng': Decimal('-1.49939775')}, u'southwest': {u'lat': Decimal('52.40551705000001'), u'lng': Decimal('-1.49992395')}}}, u'adr_address': u'Gulson Road Coventry University, <span class="locality">Coventry</span> <span class="postal-code">CV1 2JH</span>, <span class="country-name">UK</span>', u'place_id': u'ChIJV0Xu7bdLd0gRyYvYroskQ0k', u'international_phone_number': u'+44 24 7622 5719', u'vicinity': u'Coventry, Gulson Road Coventry University, Coventry', u'reviews': [{u'rating': 4, u'aspects': [{u'rating': 2, u'type': u'overall'}], u'profile_photo_url': u'//lh5.googleusercontent.com/-Ksa5MB3V150/AAAAAAAAAAI/AAAAAAAAN1g/Oc9XyOBsRAI/photo.jpg', u'language': u'en', u'text': u"It's Starbucks in EC building, save you walking in town for a hot beverage", u'author_name': u'Dhruv Bhakta', u'author_url': u'https://plus.google.com/106741921003476599081', u'time': 1453209416}], u'formatted_phone_number': u'024 7622 5719', u'scope': u'GOOGLE', u'url': u'https://maps.google.com/?cid=5279103370560834505',---> I want just that u'opening_hours': {u'weekday_text': [u'Monday: 8:00 AM \u2013 6:30 PM', u'Tuesday: 8:00 AM \u2013 6:30 PM', u'Wednesday: 8:00 AM \u2013 6:30 PM', u'Thursday: 8:00 AM \u2013 6:30 PM', u'Friday: 8:00 AM \u2013 6:00 PM', u'Saturday: Closed', u'Sunday: Closed'], u'open_now': False, u'periods': [{u'close': {u'day': 1, u'time': u'1830'}, u'open': {u'day': 1, u'time': u'0800'}}, {u'close': {u'day': 2, u'time': u'1830'}, u'open': {u'day': 2, u'time': u'0800'}}, {u'close': {u'day': 3, u'time': u'1830'}, u'open': {u'day': 3, u'time': u'0800'}}, {u'close': {u'day': 4, u'time': u'1830'}, u'open': {u'day': 4, u'time': u'0800'}}, {u'close': {u'day': 5, u'time': u'1800'}, u'open': {u'day': 5, u'time': u'0800'}}]}, <---- until here u'address_components': [{u'long_name': u'Coventry', u'types': [u'locality', u'political'], u'short_name': u'Coventry'}, {u'long_name': u'Coventry', u'types': [u'postal_town'], u'short_name': u'Coventry'}, {u'long_name': u'West Midlands', u'types': [u'administrative_area_level_2', u'political'], u'short_name': u'West Midlands'}, {u'long_name': u'England', u'types': [u'administrative_area_level_1', u'political'], u'short_name': u'England'}, {u'long_name': u'United Kingdom', u'types': [u'country', u'political'], u'short_name': u'GB'}, {u'long_name': u'CV1 2JH', u'types': [u'postal_code'], u'short_name': u'CV1 2JH'}], u'formatted_address': u'Gulson Road Coventry University, Coventry CV1 2JH, UK', u'id': u'7fd44a38d5776818e51953ee7188f10d54b768cc', u'types': [u'cafe', u'food', u'store', u'point_of_interest', u'establishment'], u'icon': u'https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png'}

详情输出如上,但我只想要时间表。

1 个答案:

答案 0 :(得分:1)

尝试谷歌文本搜索api找到place_id

https://maps.googleapis.com/maps/api/place/textsearch/json?query=StarbucksCoffee,GulsonRoad,CoventryUniversity,CoventryCV12JH,UK&key=YOUR_API_KEY

这个api将返回一个json response.Parse&#39; place_id&#39;这个地方是&#34; ChIJV0Xu7bdLd0gRyYvYroskQ0k&#34;

使用此&#39; place_id&#39;在谷歌的地方详细信息api获得开放时间

https://maps.googleapis.com/maps/api/place/details/json?ChIJV0Xu7bdLd0gRyYvYroskQ0k=&key=YOUR_API_KEY

这将返回包含开放时间的json响应