正在尝试分析data.xspf,其中Python 3.6.8和LXML 4.4.1跟在this之后,并找到<creator>Creator</creator>元素,但有[]输出。
data.xspf
<?xml version="1.0" encoding="UTF-8"?>
<playlist xmlns="http://xspf.org/ns/0/" version="1">
<title/>
<creator/>
<trackList>
<track>
<location>http://localhost:8000</location>
<creator>Creator</creator>
<title>Title</title>
<annotation>Blah
Blah
Blah
Blah
Blah
Blah
Blah</annotation>
<info>info</info>
</track>
</trackList>
</playlist>脚本:
>>> from lxml import etree
>>> tree = etree.parse("data.xspf")
>>> tree.findall('.//creator')有什么想法吗?
发布于 2019-09-03 18:44:01
使用函数的第二个参数以确保将默认名称空间考虑到tree.findall('.//creator', { None : 'http://xspf.org/ns/0/' })。
https://stackoverflow.com/questions/57768933
复制相似问题