Python script to open a Google Map location on clipboard Last Updated : 04 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The task is to create a python script that would open the default web browser to the Google map of the address given as the command line argument. Following is the step by step process: Creating the Address_string from command line input : Command line arguments can be read through sys module. The sys.argv array has the first element as the filename and the rest of elements as command line arguments which are broken into different elements by spaces, same as raw_input().split(). Therefore, if the length of sys.argv is more than 1, then we can be sure that the command line arguments have been passed. Since sys.argv is a list of strings, it can be passed to join() method which returns a single string value. Since the first element is the filename, which is not needed, we can slice the list and join from 2nd element onwards. Python #File name is Map.py import sys print ' '.join(sys.argv[1:]) If we run >>> python Map.py New Delhi The output of the program would be New Delhi. Open the Web-Browser : We will be using web browser module for opening the browser. The webbrowser module has a method open() that can launch the web browser to the specified URL. For example, the script given below will open the web browser to the home page of GeeksforGeeks. Python import webbrowser webbrowser.open('https://www.geeksforgeeks.org/') Find the URL : Now, when we go to Google Maps and search for google maps, the URL turns out to be gibberish and of no clear pattern, as shown below. https://www.google.co.in/maps/place/GeeksforGeeks/@28.5011226,77.4077907,17z/data=!3m1!4b1!4m5!3m4!1s0x390ce626851f7009:0x621185133cfd1ad1!8m2!3d28.5011226!4d77.4099794?hl=en Websites often add extra text in the URL for additional tasks like customization and tracking. However, it can be observed that the initial few part of URL is https://www.google.co.in/maps/place/GeeksforGeeks where GeeksforGeeks is our searched keyword. Also, for example say while searching for New Delhi, instead of New + Delhi, if we write only New Delhi, the + is inserted in the required places on its own, which eases our task even further. Therefore, the final URL can be taken as https://www.google.co.in/maps/place/Address_String/. Combining the two and Completing the script : The python script to open the given command line address is given below. There will be two imported modules, webbrowser to open the browser to the designated URL and sys to work on the command line arguments. The first step is to check if there is any command line given or not, which is done using the len(sys.argv). Then we use the join method to form the address string of the place that is to be searched in Google Maps. Finally, when we get the address, we open the browser to the address URL using the open() method of webbrowser module. The program is run through CMD(windows) or terminal(Linux) in the following format: >>> python [File Name] [Address to be searched] For eg. >>> python Map.py GeeksforGeeks Python # File Name -- Map.py import sys, webbrowser if len(sys.argv) > 1: # Argument passed map_string = ' '.join(sys.argv[1:]) webbrowser.open('https://www.google.com/maps/place/' + map_string) else: print "Pass the string as command line argument, Try Again" >>> python Map.py SeeksforGeeks The above command will open map of GeeksforGeeks in the web browser. Comment More infoAdvertise with us Next Article How to Add Google Maps to a Website ? H Harshit Improve Article Tags : Misc Python Web Technologies python-utility Practice Tags : Miscpython Similar Reads How to Add Google Maps to a Website ? Integrating Google Maps into a website is a common and useful feature. We can use Google Maps API to add it to our website.Follow the below steps to Add Google Maps to a Website1. Generate/Obtain Google Maps API KeyTo fetch the location data from Google Maps first we need a Google Maps API Key. It i 3 min read How to get Geolocation in Python? In this article, we will discuss on how to get Geolocation when you enter any location name and it gives all the useful information such as postal code, city, state, country etc. with the latitudes and the longitudes (the specific coordinates) and vice-versa in which we provide the coordinates to ge 2 min read Download Google Image Using Python and Selenium In this article, we are going to see how to download google Image using Python and Selenium. Installation On the terminal of your PC, type the following command. If it triggers any error regarding pip then you need to 1st install pip on windows manually by python get-pip.py command then you can run 3 min read Find the location with specified latitude and longitude using Python In this article, we are going to write a python script to find the address of a specified latitude and longitude using the geopy module. The geopy module makes it easier to locate the coordinates of addresses, cities, countries, landmarks, and zipcode. Installation: To install GeoPy module, run the 1 min read Python | Fetch Nearest Hospital locations using GoogleMaps API If you are ever curious about how you can fetch nearest places (restaurant, hospital, labs, cafe's, etc) location using your current location, this could be achieved using Python and Google Maps API. In this article, we will use Google Maps API to find the nearest hospital's locations using Python. 2 min read How To Add Google Maps With A Marker to a Website Google Maps is a web mapping service developed by Google. It offers satellite imagery, street maps, 360° panoramic views of streets (Street View), real-time traffic conditions (Google Traffic), and route planning for traveling by foot, car, bicycle (in beta), or public transportation. To add a Googl 3 min read Like