我有一个 PubMed 条目列表以及 PubMed ID。我想创建一个 python 脚本或使用接受 PubMed id 号作为输入的 python,然后从 PubMed 网站获取摘要。
到目前为止,我已经接触过 NCBI Eutilities 和 Python 中的 importurl 库,但我不知道应该如何编写模板。
任何指针将不胜感激。
谢谢,
最佳答案
使用 Biopython的模块称为 Entrez ,您可以很容易地获得摘要以及所有其他元数据。这将打印摘要:
from Bio.Entrez import efetch
def print_abstract(pmid):
handle = efetch(db='pubmed', id=pmid, retmode='text', rettype='abstract')
print handle.read()
这里是一个函数,它将获取 XML 并只返回摘要:
from Bio.Entrez import efetch, read
def fetch_abstract(pmid):
handle = efetch(db='pubmed', id=pmid, retmode='xml')
xml_data = read(handle)[0]
try:
article = xml_data['MedlineCitation']['Article']
abstract = article['Abstract']['AbstractText'][0]
return abstract
except IndexError:
return None
附言我实际上需要在实际任务中做这类事情,所以我将代码组织到一个类中 -- see this gist .
关于python - 使用 python 从 PubMed 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17409107/