看板 Python 關於我們 聯絡資訊
大家好!我是一位python的新手 目前使用ElementTree遇到了一些問題 想請教各位解決的方法 目標:嘗試自己爬出想要的資料 檔案格式:xml,http://imgur.com/rxp5q7A 問題:使用ElementTree爬資料時,印不出tag中的值,一直印出空的dictionary 程式碼: import xml.etree.ElementTree as ET import xml.etree.cElementTree as ET tree = ET.parse('councillors.xml') root = tree.getroot() for child in root: for gchild in child: print gchild.attrib 謝謝各位幫我解答^^ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.117.247.80 ※ 文章網址: http://www.ptt.cc/bbs/Python/M.1420007349.A.B5E.html
Seudo: attrib抓的是<>裡面的屬性 如<firstname value='a'/> 12/31 17:24
Seudo: 抓tag跟它的值用 gchild.tag, gchild.text 12/31 17:25
vanchy: 感謝樓上^^原來是用錯method 01/02 00:55