There are some times where we need to gather reviews of multiple places, and one of the source that we can get is from google map reviews.
Here is how I use selenium python to get google map reviews and store it into .csv files.
You are welcome to try it as well!
Before we start, lets go to the google map and pick the location that you would like to get reviews.
Scroll to the "Review Summary" and click the total reviews.
After that copy the link of it: https://www.google.com/maps/place/Mid+Valley+Megamall/...9m1!1b1
Alright, keep that link, then now back to our Python script. First, import required libraries as shown below:
Then connect your chrome driver.
Put the link that you copied into the variable name "url".
For my side, I would like to see the latest review as I will schedule it into daily basis so that our company's operation team can pick up required action as soon as possible. Therefore it is up to your requirements whether you need the same or others.
>> Hence I will navigate to "Sort" button and click "Newest" section.
After it has been sorted by newest, I will scroll till the bottom of the page so that I can extract all the required information. In the code, you will see I set 5 scrolls because I only need latest 50 reviews by daily basis. Else you will only get 10 reviews by default. Every scroll will have additional 10 reviews.
After scrolling, we need to open all the "More" under reviews. Else we will not be able to get the full reviews.
Therefore, under script section, I go to the part that stores all the reviews, you can get the xpath by using "inspection".
I created empty list as well for me to append data and convert into DataFrame.
Then I proceed to click "More" for all the reviews that has it. After that, based on the respective class that I found for name, ratings, review and the day they commented, I append all the data into the empty list that has been created.
Then we can now convert our findings into .csv file.
We are done! Happy webscraping!
You can also refer to Scraping Google Reviews with Selenium(Python)
Oh ya, let me copy paste what I found useful in this article too:
Disclaimer
While web scraping is a powerful tool, it can also lead you into ethical and legal gray areas. To start, it is possible to make hundreds of requests a second to a website. Browsing at superhuman speeds such as this is apt to get noticed. Large volumes of requests such as this are apt to bog down a website’s servers and in extreme cases could be considered a denial of service attack. Similarly, any website requiring login may contain information that is thereby not considered public and scraping said websites could leave you in legal jeopardy. The purpose of this article is solely educational.
Thanks! Have a good day!