【发布时间】:2015-08-25 14:17:29
【问题描述】:
我正在使用 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)
我现在已经能够使用元素树将数据从 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)
【问题讨论】:
标签: python xml python-3.x xml-parsing pubmed