所以我正在尝试编写一个脚本,允许搜索某个地方并获取坐标。我对这些软件包非常有限,因为我不允许下载任何python 2.7附带的软件包。
import webbrowser
location = input('Enter your location: ')
webbrowser.open('https://www.google.com/maps/place/'+location)
我的浏览器打开,网址更改为
https://www.google.com/maps/place/Washington+Monument/@38.8894838,-77.0374678,17z/data=!3m1!4b1!4m2!3m1!1s0x89b7b7a1be0c2e7f:0xe97346828ed0bfb8
从那里,我想得到新的网址,以便我可以剥离它只是有坐标。任何人都知道如何获取浏览器创建的新网址?
答案 0 :(得分: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]'
>>>
答案 1 :(得分:0)
您可以使用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