Really simple way to deal with XML in Python?

前端 未结 9 1314
Happy的楠姐
Happy的楠姐 2020-12-04 22:36

Musing over a recently asked question, I started to wonder if there is a really simple way to deal with XML documents in Python. A pythonic way, if you will.

<
9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 22:55

    I found the following python-simplexml module, which in the attempts of the author to get something close to SimpleXML from PHP is indeed a small wrapper around ElementTree. It's under 100 lines but seems to do what was requested:

    >>> import SimpleXml
    >>> x = SimpleXml.parse(urllib.urlopen('http://www.google.com/ig/api?weather=94043'))
    >>> print x.weather.current_conditions.temp_f['data']
    58
    

提交回复
热议问题