Skip to content

Commit

Permalink
Use DOI fromELocationID insted of ArticleIdList\\ArticleId (fix #135
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Michael-E-Rose authored Apr 22, 2024
2 parents 15c477a + 642e736 commit 5943a6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pubmed_parser/pubmed_web_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ def parse_pubmed_web_tree(tree):
else:
keywords = ""

doi = ""
article_ids = tree.xpath("//articleidlist//articleid")
if len(article_ids) >= 1:
for article_id in article_ids:
if article_id.attrib.get("idtype") == "doi":
doi = article_id.text
doi = tree.xpath('//elocationid[@eidtype="doi"]')
try:
doi = doi[0].text
except IndexError:
doi = None

language = tree.xpath("//language")
try:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_pubmed_web_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ def test_pubmed_web_parser_save_xml():
pubmed_dict = pp.parse_xml_web(random_id, save_xml=True)

assert "xml" in pubmed_dict

def test_doi():
"""Test the correct parsing of the doi."""
pubmed_dict = pp.parse_xml_web("32145645", save_xml=False)
assert pubmed_dict['doi'] == "10.1016/j.ejmech.2020.112186"

0 comments on commit 5943a6e

Please sign in to comment.