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?

idjaw
  • 25,487
  • 7
  • 64
  • 83
Josh Mullins
  • 13
  • 1
  • 4

2 Answers2

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]'
>>> 
xrisk
  • 3,790
  • 22
  • 45
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
Celeo
  • 5,583
  • 8
  • 39
  • 41