打印 lxml.objectify.ObjectifiedElement?

Use*_*ser 1 python lxml

打印 alxml.objectify.ObjectifiedElement只是打印一个空行,所以我必须通过它的标签访问它,当我不知道响应的标签时,我只是在猜测。

如何打印整个对象,显示孩子的名字和值?

根据要求,这是我的代码。不确定这有什么目的,但是:

from amazonproduct import API
api = API('xxxxx', 'xxxxx', 'us', 'xxxx')

result = api.item_lookup('B00H8U93JO', ResponseGroup='OfferSummary')
print result
Run Code Online (Sandbox Code Playgroud)

har*_*r07 5

使用lxml.etree.tostring()似乎有效,虽然没有美化:

>>> from lxml import etree
>>> from lxml import objectify
>>> raw = '''<root>
... <foo>foo</foo>
... <bar>bar</bar>
... </root>'''
... 
>>> root = objectify.fromstring(raw)
>>> print type(root)
<type 'lxml.objectify.ObjectifiedElement'>
>>> print etree.tostring(root)
<root><foo>foo</foo><bar>bar</bar></root>
Run Code Online (Sandbox Code Playgroud)