This Tutorial about how to write a Search and save Google maps results in Excel Script using Python and Selenium, that searches for something within a location and stores results in Excel.

In this tutorial, you’ll learn:

  • How to use selenium with Python
  • about Gecko Driver
  • How to select web-pages objects and different methods
  • How to build a scripts that manipulates Google bot with Selenium

What You Need

  • Installed Firefox browser
  • Install Gecko: Firefox Web-driver from here
  • Python 3.x
  • Selenium Package from here

Writing the code

To begin, let’s import necessary package, where the most important is Selenium:

Then you need to define the webdriver and make it open google maps as shown below. Note that at the end of each move, you need to add a pause. "time.sleep(x seconds)".

The next step is close the google consent form, and in order to do this, you need to tell the script to look for the “I accept” . Selenium provides a “switch to frame” tool when treating the widget as a independent object.

The default process within any script, you are telling the program to pick element by an identifier. Selenium provides many ways to identify page elements using a find_element_by or find_elements_by, your next step will be like this.

Selenium find_element_by methods

To get the necessary values that Identify each element, you need to copy it from the page HTML code by inspecting elements.

Right-click on the selected Elements
and copy the Xpath as Shown above

Afterwards, the code shall be written as follows:

Up to this point, the bot should be able to open Google Maps and look for something . The next step shall be store each element result to an excel file.

the next block of code is for locating the search results list and preparing the excel file.

Finally, for each entry extracting the the name, address, phone number and website, and at the end save the excel file.

Notes:

Google maps has a different layout design for special categories, so eventually the script won’t work correctly . also you should have your excel ready because the script doesn’t create the file

And that is it, good luck with your Search and save Google maps results in Excel Script . further reading would be the Selenium documentation. also below is the video for this tutorial.

Watch The video:  Google Maps Collector to Excel Using Selenium Webdriver 

checkout more python from Genius Panda

The Whole Code

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top