0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

python googlemap api を利用したデータ取得

Last updated at Posted at 2020-10-06

#概要
pythonでgoogle api を利用したデータ取得の備忘録です。
取得したデータの構造がわかりにくかったのでメモ。

apiキー取得からスクレイピングは参考サイトの通りに行いました。

#参考サイト
PythonでGoogle Places API使ってデータ取得してみた
PythonでGoogle Places APIを使って取得したデータを表示させる方法
Google Places APIで会社付近の「お食事処」を取得してみる
google api reference

#取得したファイルの構成
データを出力すると以下のようになります。


{'html_attributions': [],
 'next_page_token': 'CqQCEwEAAND0XppPuvvrCXmUQzMNptKvNU7uZqS-Rq2gRv0w9yD2ZsQDh-G1qr-hn81mrh-SWe_DG6jU2tyhjw-45yKrcPzXuOgs64avoooWYhoV68bXFGB75bH7StQLeqGzIuX30zQL5WY3MPX2Jke5aDrH45Tp28hL8LpK-vohhX3fobc9mgRJSY8HC_9_qiFOLqeYRDEdPu_dlHkqusMuALzXLYrn00-Y_hh8HdXRuAZGOyfgfn9ebP-DNdHvUZSykKfFFAfuUfuJHMv52Ilyhc4DJ4HHVLn7Kdn_5AXjyOl7JLSwHhiwXXR4FIlMziEo4IuE--fezO0oDiWJQKTHFnpuw5fAf6sEZTad1A3Hi7gRzuSHsCCeCRdwDU7Afd4bsnv7tRIQUjmDjaLVulM6S7C0y2hu_xoULb-LLjjS2Hk356DGIg_pMyFMotY',
 'results': [{'geometry': {'location': {'lat': 35.6803997, 'lng': 139.7690174},
                           'viewport': {'northeast': {'lat': 35.8174453,
                                                      'lng': 139.9188743},
                                        'southwest': {'lat': 35.519042,
                                                      'lng': 139.5628611}}},
              'icon': 'https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/geocode-71.png',
              'name': 'Tokyo',
              'photos': [{'height': 3394,
                          'html_attributions': ['<a '
                                                'href="https://maps.google.com/maps/contrib/117659812595877252927">Yujin '
                                                'Flin</a>'],
                          'photo_reference': 'CmRaAAAAqhq5iHusvG2XuIy2ytbybDLzf1Ral74YI8qLoCBU2Gr4JE1p2pSRhHs6KEF1qtZ8m2RLNW_2SqLXB6pN8anGfIcKnSNARD0Vb4xY4oOcHD2bMfTv2vtrBxO61oA3LJ9NEhDe0VxlVJns646OdP0_nxW1GhRFjIHJ4aEwUUnbrWMYpbAZcfPMpQ',
                          'width': 5000}],
              'place_id': 'ChIJXSModoWLGGARILWiCfeu2M0',
              'reference': 'ChIJXSModoWLGGARILWiCfeu2M0',
              'scope': 'GOOGLE',
              'types': ['colloquial_area', 'locality', 'political'],
              'vicinity': 'Tokyo'},
             {'business_status': 'OPERATIONAL',
              'geometry': {'location': {'lat': 35.65861110000001,
                                        'lng': 139.6997222},
                           'viewport': {'northeast': {'lat': 35.65996008029151,
                                                      'lng': 139.7010711802915},
                                        'southwest': {'lat': 35.65726211970851,
                                                      'lng': 139.6983732197085}}},
              'icon': 'https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/lodging-71.png',
              'name': 'Shibuya Excel Hotel Tokyu',
              'opening_hours': {'open_now': True},
              'photos': [{'height': 1701,
                          'html_attributions': ['<a '
                                                'href="https://maps.google.com/maps/contrib/101297695086602663090">渋谷エクセルホテル東急</a>'],
                          'photo_reference': 'CmRaAAAAzCl7D_cLECSouuCGIWrTZxi9PiZAY2SOD7VkIJaehZagYQG8IvQjCHIhhIPFXm8C1NBRSwVOj2isqVY1Y8D0J-QEXxtPg8hAUTOMIDQ2rw2H-TJQj1sYNSzAStGOzmuBEhATXspuQcWTZYdPCG3YPb39GhRMadylKeVy4oSpN4RnxPgPi-9lrQ',
                          'width': 2268}],
              'place_id': 'ChIJTzNfw1eLGGARagCmVhCOmP4',
              'plus_code': {'compound_code': 'MM5X+CV Shibuya City, Tokyo, '
                                             'Japan',
                            'global_code': '8Q7XMM5X+CV'},
              'price_level': 2,
              'rating': 4.1,
              'reference': 'ChIJTzNfw1eLGGARagCmVhCOmP4',
              'scope': 'GOOGLE',
              'types': ['lodging',
                        'restaurant',
                        'food',
                        'point_of_interest',
                        'establishment'],
              'user_ratings_total': 1853,
              'vicinity': '1 Chome-12-2 Dogenzaka, Shibuya City'},
             {'business_status': 'OPERATIONAL',
              'geometry': {'location': {'lat': 35.656286, 'lng': 139.7015866},
                           'viewport': {'northeast': {'lat': 35.6576349802915,
                                                      'lng': 139.7029355802915},
                                        'southwest': {'lat': 35.65493701970851,
                                                      'lng': 139.7002376197085}}},
              'icon': 'https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/lodging-71.png',
              'name': 'Shibuya Granbell Hotel',
              'opening_hours': {'open_now': True},
              'photos': [{'height': 3745,
                          'html_attributions': ['<a '
                                                'href="https://maps.google.com/maps/contrib/102750292639177188533">Sakurai '
                                                'Daisuke</a>'],
                          'photo_reference': 'CmRaAAAAqgA3yyukqjzUrJynEUc0MiSicVaas7mSYJtDxIYbFxjnPPSDxjEdOEcLRxGMY_zTeKH7RF_cQbsLXE1fWg6zwpG8wPkuRcyu5u6GeZyP1irGJ7hfydeLGOoQJEkah1hzEhBTXJyTR0gVkYuGwOMGr6BuGhTSiw-guLPEDDzOJWd9hXrbR9Jc3Q',
                          'width': 3000}],
              'place_id': 'ChIJkwh-41mLGGARZASpROEIZrk',
              'plus_code': {'compound_code': 'MP42+GJ Shibuya City, Tokyo, '
                                             'Japan',
                            'global_code': '8Q7XMP42+GJ'},
              'rating': 4,
              'reference': 'ChIJkwh-41mLGGARZASpROEIZrk',
              'scope': 'GOOGLE',
              'types': ['lodging', 'point_of_interest', 'establishment'],
              'user_ratings_total': 533,
              'vicinity': '15-17 Sakuragaokacho, Shibuya City'},

ネスト構造の辞書になっていて、最上位階層のキーは以下の4つで構成されています。
html_attributions
next_page_token
results
status
このうち、主なデータは'results'に入っています。
results以下もキーによってはネスト構造になっています。

評価は'rate'で表示されてますね。
レビューコメント一覧はどうやって取得するのだろうか・・・

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?