>>> et = lxml.etree.fromstring('''<item><img src="cat.jpg" /> Picture of a cat</item>''')
>>> et.find('img').tail
' Picture of a cat'
这也适用于普通元素树:
>>> import xml.etree.ElementTree
>>> xml.etree.ElementTree.fromstring(
... '''<item><img src="cat.jpg" /> Picture of a cat</item>'''
... ).find('img').tail
' Picture of a cat'
元素有一个
tail
属性——所以您需要的不是element.text
,而是element.tail
。或者,举个例子:
这也适用于普通元素树:
相关问题 更多 >
编程相关推荐