S
S
stenhot2013-12-09 14:37:11
Python
stenhot, 2013-12-09 14:37:11

How to correctly parse lxml in Python 3 so that the data of one product is written in one line of the xls file?

How to correctly parse lxml in Python 3 so that the data of one product is written in one line of the xls file? I have an outline, but when lxml encounters an empty tag, it takes the value from the next one, and I need that when an empty tag is encountered, lxml will give the tag a value of 0.

# -*- coding: utf-8 -*- from __future__ import unicode_literals 
from lxml import etree


txt = etree.parse('product.xml')

tag = etree.XPath('/doct/product/price/price/text()')

tag = tag(txt)

for l in tag:
    print(l)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dbihbka, 2013-12-09
@dbihbka

I think if the line tag = etree.XPath('/doct/product/price/price/text()') is changed to tag = etree.XPath('/doct/product/price/price') and then take text in the loop () then where it is empty it will return empty, and use this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question