繁体   English   中英

BeautifulSoup如何找到XML标签?

[英]BeautifulSoup how to find XML tag?

我有以下XML:

<xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<nite:root nite:id="ES2002a.topic" 
xmlns:nite="http://nite.sourceforge.net/">
<topic nite:id="ES2002a.topic.vkaraisk.1" other_description="introduction of participants and their roles">
  <nite:pointer role="scenario_topic_type"  href="default-topics.xml#id(top.4)"/>
  <nite:child href="ES2002a.B.words.xml#id(ES2002a.B.words0)..id(ES2002a.B.words71)"/>
  <nite:child href="ES2002a.D.words.xml#id(ES2002a.D.words0)..id(ES2002a.D.words3)"/>
  <nite:child href="ES2002a.A.words.xml#id(ES2002a.A.words0)..id(ES2002a.A.words12)"/>
  <nite:child href="ES2002a.B.words.xml#id(ES2002a.B.words72)..id(ES2002a.B.words73)"/>
  <nite:child href="ES2002a.D.words.xml#id(ES2002a.D.words4)..id(ES2002a.D.words11)"/>
  <nite:child href="ES2002a.C.words.xml#id(ES2002a.C.words0)..id(ES2002a.C.words7)"/>
  <nite:child href="ES2002a.D.words.xml#id(ES2002a.D.words12)..id(ES2002a.D.words13)"/>
</topic>

当我运行以下命令时,

[tag.name for tag in soup.find_all()]

我得到输出:

['html',
 'body',
 'nite:root',
 'topic',
 'nite:pointer',
 'nite:child',
 'nite:child',
 'topic']

但是,当我尝试将find all函数用于night:root,night:pointer,night:child时。 它返回一个空列表:

soup.find_all("nite:pointer")

返回:

[]

经过进一步的研究,我发现

soup.find_all({"nite:pointer"})

返回我正在寻找的东西

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM