我正在使用python 2.7并在
处出现错误打印'Article ID:',paper ['MedlineCitation'] ['PMID']
错误是TypeError
商品ID: 追溯(最近一次通话): 在第44行的“ F:/Practicals/Pubmed/pubmed-master/pubmed-master/scrap_pubmed.py”文件中 打印“文章ID:”,论文['MedlineCitation'] ['PMID'] TypeError:字符串索引必须为整数
if __name__ == '__main__':
print "Enter keyword to search for: "
keyword = raw_input()
print "Enter number # of articles to fetch (number): "
number_of_articles = raw_input()
results = search(keyword, number_of_articles)
id_list = results['IdList']
papers = fetch_details(id_list)
filename = 'pubmed.txt'
target = open(filename, 'w')
for i, paper in enumerate(papers):
number_of_authors = 0
print 'Article ID: ', paper['MedlineCitation']['PMID']
target.write('Article ID: ' + paper['MedlineCitation']['PMID'] + '\n')
print 'ISSN No: ', paper['MedlineCitation']['Article']['Journal']['ISSN']
target.write('ISSN No: ' + paper['MedlineCitation'][
'Article']['Journal']['ISSN'] + '\n')
答案 0 :(得分:0)
这是因为您循环错误。
您必须通过将el作为键来访问字典对象。
赞:
for i, paper in enumerate(papers):
print papers[paper][0]['MedlineCitation']['PMID']