【问题标题】:Input data to website and extract result向网站输入数据并提取结果
【发布时间】:2018-12-10 23:48:21
【问题描述】:

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

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

这可能吗?我假设我会使用 python、beautifulsoup 的组合?我在某处读到有关机械化的信息。我们将不胜感激。

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

【问题讨论】:

    标签: python beautifulsoup mechanize data-extraction


    【解决方案1】:

    上述网站使用 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))
    

    【讨论】:

    • Aaron - 感谢您提供本指南,我已经按照它进行了操作,并且有效! python是否可以从excel文件中提取地址列表并将lat/lng相应地加载回同一个文件中?我不想每月手动输入所有地址哈哈。
    • @D-Ru 看看pandas 模块,特别是read_excel 方法。它支持从 excel 文件中读取数据,然后可以在您的程序中使用。
    猜你喜欢
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    • 2012-01-12
    • 2019-05-28
    • 2015-06-25
    • 2013-08-15
    • 1970-01-01
    • 2015-03-21
    相关资源
    最近更新 更多