我正在使用此脚本从pubmed获取有关新冠肺炎的数据
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文件或文本文件的文章,任何建议,请如何做我谷歌它,但没有找到
发布于 2021-10-20 18:07:54
您可以在末尾添加此代码以保存到JSON文件中
#write to file
import json
with open('file.json', 'w') as json_file:
json.dump(papers, json_file)https://stackoverflow.com/questions/67760927
复制相似问题