Python urllib2: Receive JSON response from url

后端 未结 10 2036
轮回少年
轮回少年 2020-11-29 17:22

I am trying to GET a URL using Python and the response is JSON. However, when I run

import urllib2
response = urllib2.urlopen(\'https://api.instagram.com/v1/         


        
10条回答
  •  孤城傲影
    2020-11-29 18:14

    If the URL is returning valid JSON-encoded data, use the json library to decode that:

    import urllib2
    import json
    
    response = urllib2.urlopen('https://api.instagram.com/v1/tags/pizza/media/XXXXXX')
    data = json.load(response)   
    print data
    

提交回复
热议问题