我希望从此链接获取根节点的所有属性: http://www.sec.gov/Archives/edgar/data/75829/000144530512003029/pll-20120731.xml
Main_Page = urllib2.urlopen("http://www.sec.gov/Archives/edgar/data/75829/000144530512003029/pll-20120731.xml")
tree = ET.parse(Main_Page)
root = tree.getroot()
List=root.attrib
但是List给我看了0长度数组。那么我怎样才能获得属性值。而且它没有任何属性关键。
答案 0 :(得分:0)
请参阅ElementTree: Working with Namespaces and Qualified Names
import urllib2
from xml.etree import ElementTree as ET
Main_Page = urllib2.urlopen("http://www.sec.gov/Archives/edgar/data/75829/000144530512003029/pll-20120731.xml")
for event, (name, value) in ET.iterparse(Main_Page, ['start-ns']):
print name, ':', value
打印
country : http://xbrl.sec.gov/country/2011-01-31
dei : http://xbrl.sec.gov/dei/2011-01-31
iso4217 : http://www.xbrl.org/2003/iso4217
link : http://www.xbrl.org/2003/linkbase
pll : http://www.pall.com/20120731
us-gaap : http://fasb.org/us-gaap/2011-01-31
utreg : http://www.xbrl.org/2009/utr
xbrldi : http://xbrl.org/2006/xbrldi
xbrli : http://www.xbrl.org/2003/instance
xlink : http://www.w3.org/1999/xlink