Reputation: 49
Can you tell me how I can obtain the 5 newest articles from PubMed that contain the word 'obesity' and return the authors, the title, the date, doi and PubMed PMID of each paper using Python? Thank you in advance
EDIT:
My try so far. I believe this is the wanted result but i need to obtain the correct pubmed ids in order to run the function
from Bio.Entrez import efetch
from Bio import Entrez
Entrez.email = '[email protected]'
def print_abstract(pmid):
handle = efetch(db='pubmed', id=pmid, retmode='text', rettype='abstract')
print(handle.read())
print_abstract(pmid)
Upvotes: 3
Views: 1057
Reputation: 4461
You can use the esearch
function from Bio.Entrez
to find the UIDs of the most recent PubMed entries matching a query:
handle = Entrez.esearch(db="pubmed", term="obesity", retmax=5)
results = Entrez.read(handle)
print(results["IdList"])
By specifying term
, you can provide a query string - from your question, you're looking for entries related to "obesity". retmax
allows us to configure how many UIDs should be returned (default is 20).
When I run this now, I get the following UIDs:
['32171135', '32171042', '32170999', '32170940', '32170929']
At the time of writing, these correspond to the most recent entry UIDs when you perform the PubMed search manually. They are sorted with the most recent entry first.
Using these UIDs, your print_abstract
function performs as expected.
Upvotes: 2