【问题标题】:How to get the data from Google API如何从 Google API 获取数据
【发布时间】:2017-04-05 15:32:37
【问题描述】:

https://maps.googleapis.com/maps/api/geocode/json?address=1+acmh宾夕法尼亚+1&key =

我可以通过直接将此链接粘贴到我的浏览器中来获取数据 但我需要对许多不同的地方进行地理编码 我试过了

import json 
import re
from urllib.request import urlopen
from bs4 import BeautifulSoup

url = "https://maps.googleapis.com/maps/api/geocode/json?address=1+acmh    pennsylvania+1&key = <YOUR KEY HERE>"
content = urlopen(url).read().decode('utf-8')
info = json.loads(content)

返回“错误请求”

【问题讨论】:

  • urlopen(api)改成urlopen(url),然后你的代码就可以用了

标签: json geocode


【解决方案1】:
def getGeoInfo(name):
url = ('https://maps.googleapis.com/maps/api/geocode/json?address=%s,+PA'%name)
response = requests.get(url)
geoInfo = response.json()

找到解决方案,直接使用requests.get,甚至不需要API key!

【讨论】:

    猜你喜欢
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多