Parse XML from URL into python object

前端 未结 3 1173
轮回少年
轮回少年 2021-01-31 04:15

The goodreads website has this API for accessing a user\'s \'shelves:\' https://www.goodreads.com/review/list/20990068.xml?key=nGvCqaQ6tn9w4HNpW8kquw&v=2&shelf=toread

3条回答
  •  感情败类
    2021-01-31 04:39

    xmltodict using urllib3

    import traceback
    import urllib3
    import xmltodict
    
    def getxml():
        url = "https://yoursite/your.xml"
    
        http = urllib3.PoolManager()
    
        response = http.request('GET', url)
        try:
            data = xmltodict.parse(response.data)
        except:
            print("Failed to parse xml from response (%s)" % traceback.format_exc())
        return data
    

提交回复
热议问题