2017-04-05 46 views
0

https://maps.googleapis.com/maps/api/geocode/json?address=1+acmh賓夕法尼亞+ 1個&鍵獲取數據=如何從谷歌API

我可以通過直接在數據這個鏈接粘貼到瀏覽器 但我需要得到很多不同的地方進行地址解析 我試圖

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) 

回報 '錯誤的請求'

+0

將'urlopen(api)'改爲'urlopen(url)',那麼你的代碼適用於我 – davedwards

回答

0
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密鑰!