从url结果中获取想要的值

213 阅读1分钟
def ping_ip(extId):
    url = ''
    args = {"extId": extId}
    # headers = {'Content-Type': 'application/json'}
    res = requests.get(url, args)
    response = res.json()
    # return response
    ip_address = response['data']['publicIp']
    return ip_address

#python返回的结果data中含有列表,列表中含有多个字典,需要循环取出当中的某个值

def all_exit_id():
    url = ''
    res = requests.get(url)
    response = res.json()
    exit_id_list = []
    #循环data列表下的多个字典,取出想要的值
    for i in range(len(response['data'])):
        exit_id = response['data'][i]['extId']
        exit_id_list.append(exit_id)
    return exit_id_list