向网站输入数据并提取结果

2024-04-25 18:23:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望有人能指导我做这个小项目。你知道吗

我有一个excel文件中的地址列表,并希望将地址(可以是zipcodes)分别粘贴到下面链接的网站中,提取Long/Lat坐标并将它们粘贴到同一excel文件中的地址旁边。你知道吗

这可能吗?我假设我会使用python的组合,beautifulsoup?我在什么地方读到关于机械化的书。谢谢你的帮助。你知道吗

网址:https://www.latlong.net/convert-address-to-lat-long.html


Tags: 文件项目列表网站链接粘贴地址地方
1条回答
网友
1楼 · 发布于 2024-04-25 18:23:35

上述网站使用googlemapsapi将地址转换为坐标(称为地理编码)。要使用Google Maps API,您需要一个API密钥
您可以按照here的说明获取API密钥。你知道吗

完成后,需要安装googlemapsPython包才能使用API:
pip install googlemaps

以下代码将地址转换为坐标,并打印出给定地址所在的坐标:

import googlemaps

key = 'YOUR_API_KEY'
address = '1600 Amphitheatre Parkway' #  Google's address

gmaps = googlemaps.Client(key=key)

# Convert the given address to coordinates. You can use gmaps.reverse_geocode((lat, lng)) 
# to convert the coordinates back to an address
geocode_result = gmaps.geocode(address)

lat = geocode_result[0]['geometry']['location']['lat'] #  Get the latitude
lng = geocode_result[0]['geometry']['location']['lng'] #  Get the longitude

print(address, 'is at', (lat, lng))

相关问题 更多 >