【发布时间】:2019-04-24 08:27:24
【问题描述】:
我有一些想要解析的 xml 代码。我希望使用 ElementTree 而不是 BeautifulSoup,因为后者处理 xml 的方式存在一些问题。
我希望从以下内容中提取文本:
- 抽象/抽象文本
- ArticleId 当 IdType="pmc"
- 在检索相应的文本之前,首先检索具有“UI”值的PublicationType
我使用 ElementTree 的哪些功能来完成这项工作?
我一直在尝试使用.attrib、attrib.get()、.iter、.attrib[key] 来获取文本,但我没有成功访问实际文本。
<PubmedArticleSet>
<PubmedArticle>
<PMID Version="1">10890875</PMID>
<Journal>
<ISSN IssnType="Print">0143-005X</ISSN>
<Title>Journal of epidemiology and community health</Title>
</Journal>
<ArticleTitle>Sources of influence on medical practice.
</ArticleTitle>
<Abstract>
<AbstractText Label="OBJECTIVES" NlmCategory="OBJECTIVE">
To explore the opinion of general practitioners on the
importance and legitimacy of sources of influence on
medical practice.
</AbstractText>
<AbstractText Label="METHODS" NlmCategory="METHODS">
General practitioners (n=723) assigned to Primary Care
Teams (PCTs) in two Spanish regions were randomly selected
to participate in this study.
</AbstractText>
<AbstractText Label="RESULTS" NlmCategory="RESULTS">
The most important and legitimate sources of influence according to general practitioners were: training courses and scientific articles, designing self developed protocols and discussing with colleagues.
</AbstractText>
<AbstractText Label="CONCLUSIONS" NlmCategory="CONCLUSIONS">
The development of medical practice is determined by many factors, grouped around three big areas: organisational setting, professional system and social setting. </AbstractText>
</Abstract>
<Language>eng</Language>
<PublicationTypeList>
<PublicationType UI="D016428">Journal Article
</PublicationType>
<PublicationType UI="D013485">Research Support, Non-U.S.Gov't </PublicationType>
</PublicationTypeList>
<PubmedData>
<PublicationStatus>ppublish</PublicationStatus>
<ArticleIdList>
<ArticleId IdType="pubmed">10890875</ArticleId>
<ArticleId IdType="pmc">PMC1731730</ArticleId>
</ArticleIdList>
</PubmedData>
</PubmedArticle>
</PubmedArticleSet>
我希望得到的结果是: 生成 AbstractText 的每个“标签” 获取该“标签”的文本
【问题讨论】:
-
您能否添加一个您想要的输出示例?
标签: xml python-3.x beautifulsoup elementtree