谷歌地图网址
输入地点,返回改地点作巴黎经纬度和改经纬度对应的地点。
import xlrd
from lxml import etree
from selenium import webdriver
import time
import pandas as pd
def getadress(adress):
# 获取当前页面句柄
dizhi = ''
zuobiao = ''
normal_window = browser.current_window_handle
browser.find_element_by_xpath('//*[@id="query-input"]').send_keys(adress)
try:
xpath = browser.find_element_by_xpath('//*[@id="geocode-button"]')
xpath.click()
time.sleep(1)
# browser.implicitly_wait(10)
# browser.set_page_load_timeout(10)
# 获取所有页面句柄
all_Handles = browser.window_handles
# 如果新的pay_window句柄不是当前句柄,用switch_to_window方法切换
for pay_window in all_Handles:
if pay_window != normal_window:
browser.switch_to_window(pay_window)
try:
dizhi = etree.HTML(str(browser.page_source)).xpath(
'//*[@id="result-0"]/table/tbody/tr/td[2]/p[2]/text()')
zuobiao = etree.HTML(str(browser.page_source)).xpath(
'//*[@id="result-0"]/table/tbody/tr/td[2]/p[3]/text()')
zuobiao = zuobiao[1].strip().split('\n')[0]
dizhi = dizhi[1].strip()
except BaseException:
browser.find_element_by_xpath('//*[@id="query-input"]').clear()
print('坐标无法查找:', adress)
# print('坐标:', zuobiao[1].strip().split('\n')[0])
# print('坐标地点:', dizhi[1].strip())
browser.find_element_by_xpath('//*[@id="query-input"]').clear()
except BaseException:
print('错误:无搜索按键!')
browser.find_element_by_xpath('//*[@id="query-input"]').clear()
return zuobiao, dizhi
if __name__=='__main__':
url = "https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/utils/geocoder"
browser = webdriver.Chrome()
browser.get(url=url)
browser.implicitly_wait(10)
time.sleep(5)
dizhi = input('输入地址:')
print(getadress(dizhi ))