0

I am using this script to get data about covid-19 from 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']))

I get results in console but what I want is to automatically download files like XML files or text files of articles, any suggestions please on how to do that I googled it but nothing found

  • Does this answer your question? [Downloading all full-text articles in PMC and PubMed databases](https://stackoverflow.com/questions/47293387/downloading-all-full-text-articles-in-pmc-and-pubmed-databases) – Jan Wilamowski Jun 08 '21 at 09:24

1 Answers1

0

You can add this code at the end to save to a JSON file

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