diff --git a/pubmed_parser/pubmed_web_parser.py b/pubmed_parser/pubmed_web_parser.py index 2825681..fc401da 100644 --- a/pubmed_parser/pubmed_web_parser.py +++ b/pubmed_parser/pubmed_web_parser.py @@ -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: diff --git a/tests/test_pubmed_web_parser.py b/tests/test_pubmed_web_parser.py index 2062240..5b47e9a 100644 --- a/tests/test_pubmed_web_parser.py +++ b/tests/test_pubmed_web_parser.py @@ -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"