urllib と ElementTree を使用して、pubmed からの XML API 呼び出しを解析しています。
これの例は次のとおりです。
#Imports Modules that can send requests to URLs
#Python Version 3.4 Using IEP (Interactive Editor for Python) as IDE
import urllib.request
import urllib.parse
import re
import xml.etree.ElementTree as ET
from urllib import request
#Obtain API Call and assign Element Object to Root
id_request = urllib.request.urlopen('http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=1757056')
id_pubmed = id_request.read()
root = ET.fromstring(id_pubmed)
Element Tree を使用して、データを ET.fromstring からオブジェクト ルートにインポートできるようになりました。私の問題は、このオブジェクトから興味深い要素を見つけるのに苦労していることです。
私は参照しています: https://docs.python.org/2/library/xml.etree.elementtree.html と私の XML 形式は次のようになります: http://eutils.ncbi.nlm.nih.gov/entrez/eutils /esummary.fcgi?db=pubmed&id=1757056
私が試してみました:
#Parse Attempts. Nothing returned.
for author in root.iter('Author'):
print (author.attrib)
としても
#No Return for author
for author in root.findall('Id'):
author = author.find('author').text
print (author)