python - 从谷歌地图中抓取城市的经度和纬度
问题描述
我想从谷歌地图中提取一个城市的纬度和经度。流程应该是这样的
打开谷歌地图 URL 搜索一个城市说“纽约”
现在我想获取这个城市的纬度和经度。任何帮助,将不胜感激。提前谢谢。
解决方案
我可以用context_click
硒来做。
wait = WebDriverWait(driver, 10)
driver.get("https://www.google.com/maps")
wait.until(EC.element_to_be_clickable((By.ID, "searchboxinput"))).send_keys("New York")
wait.until(EC.element_to_be_clickable((By.ID, "searchbox-searchbutton"))).click()
sleep(5)
ActionChains(driver).move_to_element(driver.find_element_by_xpath("//html/body")).context_click().perform()
print(wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "ul[role='menu']>li div div[class*='text']:nth-of-type(1)"))).text)
输出/输出:
40.69715, -74.25987
不要忘记导入这些:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
推荐阅读
- nginx - 我无法使用 nginx-reverse-proxy 正确重定向
- typescript - 有没有办法在 Typescript 中访问 firebase 函数返回?
- python-3.x - Odoo14:将 Many2many 与 Many2one 联系起来
- python - Scikit Learn 中的分类朴素贝叶斯给出了 IndexError
- php - PHP password_hash 导致问题
- django - Django - 如何在视图的 GET 方法部分访问 POST 数据而不将数据保存在数据库中?
- tsql - 将文本时间转换为 DateTime 从时间中删除前导 0
- android - 有没有办法对齐 LazyColumn 底部的项目?
- windows - 根据 Windows 版本运行的批处理脚本
- python - 使用 Scikit-Learn 的 GridSearchCV 捕获所有排列的精度、召回率和 f1?