python - 单击“提交”按钮后使用 Python 获取新 URL

标签 python web-scraping get geolocation gps

我正在使用 Google map 来获取我正在搜索的地址的 GPS 坐标。我想在点击提交后获取 URL,以便我可以从 URL 中提取 GPS 坐标。但是我的网址只显示: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) 

最佳答案

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

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,+亚特兰大,+GA+30314,+USA/@33.7500669,-84.4211224,17z/data=!3m1!4b1 !4m5!3m4!1s0x88f5035d3de5336f:0x9ca82913b5ecbde!8m2!3d33.7500669!4d-84.4189284

关于python - 单击“提交”按钮后使用 Python 获取新 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54621726/

相关文章:

python - 如何在父子关系上组合两个数据帧(介于连接和合并之间)

javascript - 使用 nightmarejs 单击图像

PYTHON - BEAUTIFULSOUP 如何将空 TD(表数据)刮取为空值而不是跳过它

python - 从 python 中的正则表达式数组输出中提取非空值

python - 隔离林实现

Python PyQt5 - QEvent Keypress 执行两次

html - 使用 CodeIgniter 获取 URL 中的参数

python - 确定网站是否是网上商店

javascript - 访问器(accessor)描述符 : How to use 'get' and 'set' in practice?

java - 从 mysql 获取日期