我有這個代碼正在工作,但我怎樣才能加載項目值而不是對象本身,並將其記錄到數組中。使用Python加載XML數據
import urllib
import xml.etree.ElementTree as xml
tree = xml.parse(urllib.urlopen('http://lazhalazha.livejournal.com/data/rss'))
rootElement = tree.getroot()
for a in rootElement.findall('channel/item/guid'):
print a
輸出
<Element 'guid' at 0xb75316ec>
<Element 'guid' at 0xb7531a0c>
<Element 'guid' at 0xb7531c8c>
<Element 'guid' at 0xb7531f0c>
<Element 'guid' at 0xb753a22c>
<Element 'guid' at 0xb753a4ec>
<Element 'guid' at 0xb753a7ac>
<Element 'guid' at 0xb753aa6c>
<Element 'guid' at 0xb753ad2c>
'urllib'是不必要的。 'xml.parse(theurl)'可以正常工作。 – 2012-03-06 18:55:20