from lxml import etree
xml = """<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<books>
<book author="1">Johnny Dape</book>
<book >Al Pacino</book>
<book author="3">Robert De Niro</book>
<book author="4">Kevin Spacey</book>
<book >Denzel Washington</book>
</books>
</root>"""
How to make XPath return 'None' in Python if no attribute found?