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.
[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
[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'])
{'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