单击提交按钮后使用 Python 获取新的 URL

Using Python to get new URL after clicking Submit button

我正在使用 Google 地图获取我正在搜索的地址的 GPS 坐标。我想在点击提交后获取 URL,以便我可以从 URL 中提取 GPS 坐标。但是我的 URL 只显示:https://www.google.com/maps

        url = "http://maps.google.com/"
        locationAdrs = '957 ASHBY GROVE SW ATLANTA' 
        browser = webdriver.Chrome(executable_path="C:/Users/joe/AppData/Local/Programs/Python/Python37-32/PyOn/chromedriver")
        browser.get(url)
        address = browser.find_element_by_xpath('//*[@id="searchboxinput"]')
        address.send_keys(locationAdrs)
        address.submit()
        url = browser.current_url
        print(url) 

您必须重新确认实际访问的 link 是什么,因为您输入的 link 可能与最终将您连接到最终目的地的 DNS 路由不对应。然后你必须等待你的浏览器更新,然后你 return 你正在访问的新地址:

url = "https://www.google.com/maps"
locationAdrs = '957 ASHBY GROVE SW ATLANTA'
browser.get(url)
address = browser.find_element_by_xpath('//*[@id="searchboxinput"]')
address.send_keys(locationAdrs)
# address.submit() - doesn't seem to do the right thing.
url = browser.current_url # have initial url on same format before click is made to move away
browser.find_element_by_xpath('//*[@id="searchbox-searchbutton"]').click()
while url == browser.current_url:
    time.sleep(2)
url = browser.current_url
print(url)

输出: https://www.google.com/maps/place/957+Ashby+Grove+SW,+Atlanta,+GA+30314,+USA/@33.7500669,-84.4211224,17z/data=!3m1!4b1!4m5!3m4!1s0x88f5035d3de5336f:0x9ca82913b5ecbde!8m2!3d33.7500669!4d-84.4189284