Я не знаю как, но element.find('./@attrname')
повышает KeyError: '@'
код
import lxml.etree as ET
with open(self.filepaths[0]) as f:
root = ET.parse(f)
root = root.getroot()
namespaces = {'xmlns': 'http://www.iai-shop.com/developers/iof/extensions.phtml',
"xml": "http://www.w3.org/XML/1998/namespace"}
items = root.findall('.//product', namespaces)
for item in items:
name = item.find('./description/short_desc[@xml:lang="pol"]', namespaces).text
try:
desc = item.find('./description/long_desc[@lang="pol"]', namespaces).text
except AttributeError:
desc = None
code = item.find('./@code_on_card',namespaces)
Я пытаюсь получить атрибут code_on_card
из<product type="xxx" id="xxx" vat="23.0" code_on_card="xxx">
Знаете ли вы, в чем проблема?