所以這個工作得很好,但record.get( 「SO」), 「?」)只返回該雜誌
沒有的縮寫它沒有。它甚至不會因這條線運行:
records = list(records)
爲records
沒有定義。即使你解決這個問題,你得到回:
idlist = record["IdList"]
就像號碼清單:即旨在傳遞通過Entrez.efetch()
回調得到實際數據['17510654', '2246389']
。所以當你在這些數字串中的一個上做record.get("SO", "?")
時,你的代碼就會再次出現。
首先,"SO"
字段縮寫定義爲返回期刊標題縮寫(TA)作爲其返回的一部分。您可能需要使用"JT"
Journal Title,而不是MEDLINE/PubMed Data Element (Field) Descriptions中定義的。但是這些都與這個查詢沒有任何關係。
這是你的代碼的返工,以獲得文章的標題,它是在該雜誌的標題:
from Bio import Entrez
Entrez.email = "[email protected]" # change this to be your email address
handle = Entrez.esearch(db="pubmed", term="cancer AND wombats", retmax=20)
record = Entrez.read(handle)
handle.close()
for identifier in record['IdList']:
pubmed_entry = Entrez.efetch(db="pubmed", id=identifier, retmode="xml")
result = Entrez.read(pubmed_entry)
article = result['PubmedArticle'][0]['MedlineCitation']['Article']
print('"{}" in "{}"'.format(article['ArticleTitle'], article['Journal']['Title']))
輸出
> python3 test.py
"Of wombats and whales: telomere tales in Madrid. Conference on telomeres and telomerase." in "EMBO reports"
"Spontaneous proliferations in Australian marsupials--a survey and review. 1. Macropods, koalas, wombats, possums and gliders." in "Journal of comparative pathology"
>
詳細信息可以在文檔中找到: MEDLINE PubMed XML Element Descriptions