gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:21:10 24 4
gpt4 key购买 nike

我希望有人可以指导我完成这个小项目。

我在 excel 文件中有一个地址列表,我想将地址(可以是邮政编码)单独粘贴到下面链接的网站中,然后提取经纬度坐标并将它们粘贴到同一个 excel 文件中的地址旁边。

这可能吗?我假设我会使用 python,beautifulsoup 的组合?我在某处阅读了有关 Mechanize 的信息。您的帮助将不胜感激。

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

最佳答案

提到的网站使用 Google Maps API 将地址转换为坐标(称为地理编码)。为了能够使用 Google Maps API,您需要一个 API key
您可以按照说明操作 here关于如何获取 API key 。

完成后,您需要安装 googlemaps能够使用 API 的 Python 包: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))

关于python - 向网站输入数据并提取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51141430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com