【问题标题】:can't retrieving files from pubmed using biopython无法使用 biopython 从 pubmed 检索文件
【发布时间】:2021-05-30 12:05:05
【问题描述】:

我正在使用此脚本从 pubmed 获取有关 covid-19 的数据

from Bio import Entrez
    def search(query):
        Entrez.email = 'your.email@example.com'
        handle = Entrez.esearch(db='pubmed', 
                                sort='relevance', 
                                retmax='20',
                                retmode='xml', 
                                term=query)
        results = Entrez.read(handle)
        return results
    
    def fetch_details(id_list):
        ids = ','.join(id_list)
        Entrez.email = 'your.email@example.com'
        handle = Entrez.efetch(db='pubmed',
                               retmode='xml',
                               id=ids)
        results = Entrez.read(handle)
        return results
    
    if __name__ == '__main__':
        results = search('covid-19')
        id_list = results['IdList']
        papers = fetch_details(id_list)
        for i, paper in enumerate(papers['PubmedArticle']):
            print("{}) {}".format(i+1, paper['MedlineCitation']['Article']['ArticleTitle']))

我在控制台中得到结果,但我想要的是自动下载诸如 XML 文件或文章文本文件之类的文件,请就如何做到这一点提出任何建议,我用谷歌搜索了它,但没有找到

【问题讨论】:

标签: biopython pubmed


【解决方案1】:

您可以在末尾添加此代码以保存到 JSON 文件中

#write to file 
import json
with open('file.json', 'w') as json_file:
      json.dump(papers, json_file)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多