首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用LXML通过标记在XML中找到元素

无法使用LXML通过标记在XML中找到元素
EN

Stack Overflow用户
提问于 2019-09-03 17:36:18
回答 1查看 56关注 0票数 2

正在尝试分析data.xspf,其中Python 3.6.8LXML 4.4.1跟在this之后,并找到<creator>Creator</creator>元素,但有[]输出。

data.xspf

代码语言:javascript
复制
<?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>

脚本:

代码语言:javascript
复制
>>> from lxml import etree

>>> tree = etree.parse("data.xspf")
>>> tree.findall('.//creator')

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-03 18:44:01

使用函数的第二个参数以确保将默认名称空间考虑到tree.findall('.//creator', { None : 'http://xspf.org/ns/0/' })

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57768933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档