Get reviews with python googlemap api

Overview

The ultimate goal is to create a website that ranks scraped stores with reference to word of mouth.

This is a continuation of the previous time (Data acquisition using python googlemap api). I was able to get store information using the api, but I had a hard time getting word-of-mouth because the'reviews' parameter did not exist.

Reference site

[Get reviews from Google Map API](https://www.it-swarm-ja.tech/ja/google-maps/google-map-api%E3%81%8B%E3%82%89%E3 % 83% AC% E3% 83% 93% E3% 83% A5% E3% 83% BC% E3% 82% 92% E5% 8F% 96% E5% BE% 97% E3% 81% 99% E3% 82 % 8B / 1073688155 /) I tried to get the data of Google API and Gurunavi API with Python

What i did

[Get reviews from Google Map API](https://www.it-swarm-ja.tech/ja/google-maps/google-map-api%E3%81%8B%E3%82%89%E3 % 83% AC% E3% 83% 93% E3% 83% A5% E3% 83% BC% E3% 82% 92% E5% 8F% 96% E5% BE% 97% E3% 81% 99% E3% 82 Looking at% 8B / 1073688155 /), it seems that'place_id'and'api_key' can access the data with'review'.

I was able to retrieve the reviews by doing the following. The reason for using the ast module is that I wanted to convert the XML format data acquired by bs4 into a dictionary type and retrieve only the reviews.

It seems that you can only get up to 5 items, so we will search for a way to sort and retrieve by other factors such as time.


key = 'AIzaSyDdKdbQVGfN2SgQ2BNEkwAPhK1enpJzk_c' #Enter the API key created above
placeId = 'ChIJJ4-os2znAGAReJ4AQRGTrcs'

urlName = "https://maps.googleapis.com/maps/api/place/details/json?placeid={0}&key={1}".format(placeId,key)
dataHTML = requests.get(urlName)
soup = BeautifulSoup(dataHTML.content, "html.parser")

soup = ast.literal_eval(str(soup))
pprint.pprint(soup['result']['reviews'])

Execution result

 {'author_name': 'Susie Mead',
  'author_url': 'https://www.google.com/maps/contrib/109736572258034599657/reviews',
  'language': 'en',
  'profile_photo_url': 'https://lh5.googleusercontent.com/-yaP8l2DOlaE/AAAAAAAAAAI/AAAAAAAAAAA/AMZuucnHsZcunKg758to4D5rIfeVjwMqZg/s128-c0x00000000-cc-rp-mo/photo.jpg',
  'rating': 2,
  'relative_time_description': 'a year ago',
  'text': 'The hotel is located in a really interesting area filled with shops '
          'and markets. The room was nice and updated. My downside is the '
          'building was hard to find and no English signs at all and the staff '
          'barley speak English making it very difficult to communicate.',
  'time': 1562469388},
 {'author_name': 'whenuaboynton',
  'author_url': 'https://www.google.com/maps/contrib/118063609090864700050/reviews',
  'language': 'en',
  'profile_photo_url': 'https://lh3.googleusercontent.com/a-/AOh14GjXy-z98y7u9l702EwHvz5DN6AqQWihDh3Fsp-V=s128-c0x00000000-cc-rp-mo',
  'rating': 5,
  'relative_time_description': 'a year ago',
  'text': 'Double room was amazing, biggest bed I’ve ever seen or slept on. '
          'Room far bigger than others experienced in Japan. Couldn’t get a '
          'better location in Osaka.',
  'time': 1569917795}]

Recommended Posts

Get reviews with python googlemap api
[Python] Get Python package information with PyPI API
Get date with python
Get stock price data with Quandl API [Python]
Get Gmail subject and body with Python and Gmail API
Get country code with python
Use Trello API with python
Get Twitter timeline with python
Use Twitter API with Python
Get Youtube data with python
Get information with zabbix api
Web API with Python + Falcon
Get thread ID with python
Play RocketChat with API / Python
Get started with Python! ~ ② Grammar ~
Call the API with python3.
Use subsonic API with python3
Get stock price with Python
Get home directory with python
Get keyboard events with python
Get Alembic information with Python
Get ranking with Rakuten API
[First API] Try to get Qiita articles with Python
Get schedule from Garoon SOAP API with Python + Zeep
[Python] Get user information and article information with Qiita API
Create Awaitable with Python / C API
Data acquisition using python googlemap api
Link to get started with python
Run Rotrics DexArm with python API
Quine Post with Qiita API (Python)
Get the weather with Python requests
Get web screen capture with python
Get the weather with Python requests 2
[Python] Get economic data with DataReader
How to get started with Python
Hit the Etherpad-lite API with Python
[python] Read information with Redmine API
[Small story] Get timestamp with Python
Get Qiita trends with Python scraping
Get upcoming weather from python weather api
Get data from analytics API with Google API Client for python
Get started with Python in Blender
Get weather information with Python & scraping
Get US stock price from Python with Web API with Raspberry Pi
Collecting information from Twitter with Python (Twitter API)
Get additional data in LDAP with python
Get property information by scraping with python
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
Simple Slack API client made with Python
Retrieving food data with Amazon API (Python)
[Python] Get the variable name with str
Get Google Fit API data in Python
Get Youtube data in Python using Youtube Data API
Get Started with TopCoder in Python (2020 Edition)
[Python] Quickly create an API with Flask
Get holidays with the Google Calendar API
Serverless face recognition API made with Python
How Python beginners get started with Python with Progete
Let's get along with Python # 0 (Environment construction)
Get coincheck virtual currency information with API ♪