import os
import xml.etree.ElementTree
from xml.etree import ElementTree
file_name = 'pubmed21n0001.xml'
full_file = os.path.abspath(os.path.join('data', file_name))
dom = ElementTree.parse(full_file)
pubmed = dom.findall('PubmedArticle/MedlineCitation')
for p in pubmed:
LastName = p.find('Article/AuthorList/Author/LastName').text
ForeName = p.find('Article/AuthorList/Author/ForeName').text
Initials = p.find('Article/AuthorList/Author/Initials').text
print('{}_{}_{}'.format(LastName, ForeName, Initials))
this is the python code i wrote
<root>
<PubmedArticle>
<MedlineCitation Status="MEDLINE" Owner="NLM">
<Article PubModel="Print">
<AuthorList CompleteYN="Y">
<Author ValidYN="Y">
<LastName>Makar</LastName>
<ForeName>A B</ForeName>
<Initials>AB</Initials>
</Author>
<Author ValidYN="Y">
<LastName>McMartin</LastName>
<ForeName>K E</ForeName>
<Initials>KE</Initials>
</Author>
<Author ValidYN="Y">
<LastName>Palese</LastName>
<ForeName>M</ForeName>
<Initials>M</Initials>
</Author>
<Author ValidYN="Y">
<LastName>Tephly</LastName>
<ForeName>T R</ForeName>
<Initials>TR</Initials>
</Author>
</AuthorList>
</Article>
</MedlineCitation>
</PubmedArticle>
</root>
如何解析多个名称? 如果我运行代码,只会打印一个名称 这是pubmed21n001.xml文件的简明版本 原始档案中有很多
进一步进入括号:
试试下面的方法
输出
相关问题 更多 >
编程相关推荐