美文网首页
python 解析xml

python 解析xml

作者: 7鸩羽千夜7 | 来源:发表于2017-05-13 11:41 被阅读0次

# -*- coding: utf-8 -*-

from lxml import etree

h_3 = etree.HTML(t_1)#将xml内容 格式化

n_2 = h_3.xpath('//text()')#定位 所有的文字内容

注意:要定位需要的内容时路径前面要加 /html/body/

如 :n_2 = h_3.xpath('/html/body/listordersresponse/listordersresult/orders/order[1]/latestshipdate/text()')

还有要把路径中的所有大写改为小写

print(n_2)#打印定位到的内容

相关文章

网友评论

      本文标题:python 解析xml

      本文链接:https://www.haomeiwen.com/subject/jbdxxxtx.html