One option is to use getchildren()
method:
for cell in set:
print "stage1" if cell.getchildren() else "stage2"
prints:
stage1
stage2
Since the first td
has span
inside, the second td
doesn't have any children.
UPD:
for cell in set:
children = cell.getchildren()
if not children:
print "stage2"
else:
print "stage1"
for child in children:
print child.xpath('node()')[0].strip()