I am using XPath with Python lxml (Python 2). I run through two passes on the data, one to select the records of interest, and one to extract values from the data. Here is a
You should try following:
for node in nodes:
print node.attrib
This will return dict of all attributes of node as {'id': '1', 'weight': '80', 'height': '160'}
If you want to get something like [('@id', '1'), ('@height', '160'), ('@weight', '80')]
:
list_of_attributes = []
for node in nodes:
attrs = []
for att in node.attrib:
attrs.append(("@" + att, node.attrib[att]))
list_of_attributes.append(attrs)
Output:
[[('@id', '1'), ('@height', '160'), ('@weight', '80')], [('@id', '2'), ('@weight', '70')], [('@id', '3'), ('@height', '140')]]