如何编写 Python 代码从 PubMed 下载摘要?

发布于 2025-01-17 05:43:57 字数 305 浏览 1 评论 0原文

这是我现在拥有的代码,我尝试了多种不同的方法来获取正确的代码,但无济于事。

我为此使用 Biopython 模块。

from Bio.Entrez import efetch

def print_abstract(pmid):
    handle = efetch(db='pubmed', id=pmid, retmode='text', rettype='abstract')
    print handle.read()

我尝试了上面列出的代码以及此处和那里的一些调整,但似乎没有任何内容适用于简单的查询。

This is the code I have as of now and I have tried multiple different ways to get the correct code but to no avail.

I am using the Biopython module for this.

from Bio.Entrez import efetch

def print_abstract(pmid):
    handle = efetch(db='pubmed', id=pmid, retmode='text', rettype='abstract')
    print handle.read()

I tried the code as listed above along with a few tweaks here and there but nothing seems to be working for a simple query.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自在安然 2025-01-24 05:43:57

第 1 步:使用 python3 时,请按如下方式使用 print()

from Bio.Entrez import efetch
 
def print_abstract(pmid):
    handle = efetch(db='pubmed', id=pmid, retmode='text', rettype='abstract')
    print(handle.read())

第 2 步:要使用 NCBI 的电子实用程序,NCBI 要求您在每个请求中指定您的电子邮件地址。因此,指定任何电子邮件(不必是真实的),如下所示:

from Bio import Entrez                                                                                                                                                                                          
Entrez.email = '[email protected]'                                                                                                                                                                          

步骤 3:现在您可以以编程方式检索摘要,例如通过运行

print_abstract(35312860)

这给了我:

1. Acta Diabetol. 2022 Mar 21. doi: 10.1007/s00592-022-01878-z. [Epub ahead of 
print]                                                                                                   
                                                                                                         
Significant and persistent improvements in time in range and positive emotions in
children and adolescents with type 1 diabetes using a closed-loop control system 
after attending a virtual educational camp.                                                              
...
OBJECTIVE: To evaluate the six-month impact of the advanced automated functions...                                                                                                  

Step 1: When using python3, use print() as such:

from Bio.Entrez import efetch
 
def print_abstract(pmid):
    handle = efetch(db='pubmed', id=pmid, retmode='text', rettype='abstract')
    print(handle.read())

Step 2: To make use of NCBI's E-utilities, NCBI requires you to specify your email address with each request. So, specify any email (it doesn't have to be real) as follows:

from Bio import Entrez                                                                                                                                                                                          
Entrez.email = '[email protected]'                                                                                                                                                                          

Step 3: Now you can retrieve an abstract programmatically, for example by running

print_abstract(35312860)

This gives me:

1. Acta Diabetol. 2022 Mar 21. doi: 10.1007/s00592-022-01878-z. [Epub ahead of 
print]                                                                                                   
                                                                                                         
Significant and persistent improvements in time in range and positive emotions in
children and adolescents with type 1 diabetes using a closed-loop control system 
after attending a virtual educational camp.                                                              
...
OBJECTIVE: To evaluate the six-month impact of the advanced automated functions...                                                                                                  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文