我知道已经有很多答案了,所以要处理splitpython的URL。但是,我想拆分一个URL,然后在函数中使用它
我在python中使用了一个curl请求:
r = requests.get('http://www.datasciencetoolkit.org/twofishes?query=New%York')
r.json()
它提供了以下内容:
{'interpretations': [{'what': '',
'where': 'new york',
'feature': {'cc': 'US',
'geometry': {'center': {'lat': 40.742185, 'lng': -73.992602},
......
# (lots more, but not needed here)
我想能够给任何城市/地点打电话,我想把lat
和lng
分开。例如,我想调用一个可以输入任何城市的函数,它用经纬度来响应。有点像this question(使用R)
这是我的尝试:
import requests
def lat_long(city):
geocode_result = requests.get('http://www.datasciencetoolkit.org/twofishes?query= "city"')
我如何解析它,这样我就可以调用一个城市的函数
以你的例子,我建议使用正则表达式和字符串插值。这个答案假设API每次都以相同的方式返回数据
您可以在这个列表上循环查找城市名称,并在找到正确的城市时返回坐标
相关问题 更多 >
编程相关推荐