1

So I am trying to write a script that will allow to search for a certain place and get the coordinates. I am very limited with the packages because I'm not allow download any packages that does not already comes with python 2.7.

import webbrowser

location = input('Enter your location: ')

webbrowser.open('https://www.google.com/maps/place/'+location)

My browser opens and the url changes to

https://www.google.com/maps/place/Washington+Monument/@38.8894838,-77.0374678,17z/data=!3m1!4b1!4m2!3m1!1s0x89b7b7a1be0c2e7f:0xe97346828ed0bfb8

From there, I want to get the new url so I can strip it to just have the coordinates. Anyone one know how to get the new url the browser creates?

2
  • If the user is entering the location information, why not just strip the coordinates from there? Why bother with a browser at all? Commented Nov 2, 2015 at 21:06
  • @JohnGordon the user will enter something like Washington. Commented Nov 2, 2015 at 21:06

2 Answers 2

1
>>> import urllib
>>> text = urllib.urlopen('https://www.google.com/maps/place/washington').read()
>>> p = text.find('cacheResponse([[[')
>>> p
228
>>> text[228: 300]
'cacheResponse([[[26081602.52827102,-95.67706800000001,37.06250000000001]'
>>> 
Sign up to request clarification or add additional context in comments.

Comments

0

You could use Selenium's Python library:

>>> from selenium import webdriver
>>> driver = webdriver.Firefox()
>>> driver.get('https://www.google.com/maps/place/Washington')
>>> driver.current_url
https://www.google.com/maps/place/Washington,+DC/@38.8992651,-77.1546507,11z/data=!3m1!4b1!4m2!3m1!1s0x89b7c6de5af6e45b:0xc2524522d4885d2a

1 Comment

OP says he is not allowed to install any packages. However good approach nonetheless

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.