problem in code to retrieve articles titles from pubmed
0
0
Entering edit mode
8.2 years ago

Hi there,

I am trying to fetch author names and articles' titles from pubmed. The only issue in this code is, it is giving title of articles in this form: ['R', 'o', 'u', 't', 'i', 'n', 'e', ' ', 'A', 'm', 'o', 'x', 'i', 'c', 'i', 'l', 'l', 'i', 'n', ' ', 'f', 'o', 'r', ' ', 'U', 'n', 'c', 'o', 'm', 'p', 'l', 'i', 'c', 'a', 't', 'e', ']

I mean separating each character with ' '. I want to get the names in a proper way. I am learner of python. please anyone help me out.

from Bio import Entrez
from Bio import Medline

MAX_COUNT = 15
TERM = 'clinicaltrials.gov+[si]'

#print("getting %d publications containing %s" % (MAX_COUNT,TERM))

print('Getting {0} publications containing {1}...'.format(MAX_COUNT, TERM))
Entrez.email = 'A.N.Other@example.com'
h = Entrez.esearch(db='pubmed'**, retmax=MAX_COUNT, term=TERM)
result = Entrez.read(h)
print('Total number of publications containing {0}: {1}'.format(TERM, result['Count']))

ids = result['IdList']
h = Entrez.efetch(db='pubmed', id=ids, rettype="Medline", retmode='text')
records = Medline.parse(h)

authors = []
titles=[]
for record in records:
    #print(record)
    au = record.get('AU', '?')
    title=record.get("TI","?")
    # print(au)
    for a in au:
        #if a,b not in authors,t:
        authors.append(a)
    for t in title:
        titles.append(t)
    authors.sort()
print('Authors: {0} '.format(', '.join(authors)))
print(titles)
python pubmed • 2.0k views
ADD COMMENT
1
Entering edit mode

I am not a Python programmer but assuming that the variable title contains only one title then this code:

    for t in title:
        titles.append(t)

is taking single elements of title (i.e. characters) and adds then to an array named titles so titles ends up being a list of characters contained in title. Just stick to your title variable and if you want to add it to a list of titles then do

titles.append(title)
ADD REPLY

Login before adding your answer.

Traffic: 2498 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6