How do I parse a JSON response from Python Requests?

后端 未结 7 1218
悲&欢浪女
悲&欢浪女 2021-02-19 00:09

I am trying to parse a response.text that I get when I make a request using the Python Requests library. For example:

def check_user(s         


        
7条回答
  •  清酒与你
    2021-02-19 00:43

    If the response is in json you could do something like (python3):

    import json
    import requests as reqs
    
    # Make the HTTP request.
    response = reqs.get('http://demo.ckan.org/api/3/action/group_list')
    
    # Use the json module to load CKAN's response into a dictionary.
    response_dict = json.loads(response.text)
    
    for i in response_dict:
        print("key: ", i, "val: ", response_dict[i])
    

    To see everything in the response you can use .__dict__:

    print(response.__dict__)
    

提交回复
热议问题