gpt4 book ai didi

python - 如何通过BioPython自动将PMC全文保存到磁盘?

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:15 25 4
gpt4 key购买 nike

有没有办法下载并保存Entrez模块返回到本地磁盘的XML文件?我目前正在做的是:

fetch = Entrez.efetch(db='pmc',
resetmode='xml',
id=ids,
rettype='full')
article = fetch.read()

然后通过Python的write函数将article(即str对象)保存为xml文件。

BioPython 是否提供了自动将文件下载到磁盘上的方法?

最佳答案

我不认为 Biopython 提供了执行此操作的方法,但它不需要这样做,因为您无需先保存到字符串即可执行此操作:

fetch = Entrez.efetch(db='pmc',
resetmode='xml',
id=ids,
rettype='full')

with open('fileNameToSave.xml', 'w') as f:
f.write(fetch.read())

正如 Chris_Rands 在评论中指出的那样,另一种方法是直接通过 URL 获取文件:

https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=protein&id=15718680

关于python - 如何通过BioPython自动将PMC全文保存到磁盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43350347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com