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

时间:2018-07-02 17:55:33

标签: python beautifulsoup mechanize data-extraction

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

我在excel文件中有一个地址列表,想将这些地址(可以是邮政编码)分别粘贴到下面链接的网站中,并提取经纬度坐标,并将其粘贴到同一excel文件中的地址旁边

这可能吗?我假设我会使用python,Beautifulsoup的组合?我读过有关机械化的文章。您的帮助将不胜感激。

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

1 个答案:

答案 0 :(得分:0)

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

完成后,您需要安装googlemaps Python软件包才能使用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))
相关问题