作者vanchy (vanchy)
看板Python
标题[问题] 请教elementtree的问题
时间Wed Dec 31 14:29:07 2014
大家好!我是一位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://webptt.com/cn.aspx?n=bbs/Python/M.1420007349.A.B5E.html
1F:推 Seudo: attrib抓的是<>里面的属性 如<firstname value='a'/> 12/31 17:24
2F:→ Seudo: 抓tag跟它的值用 gchild.tag, gchild.text 12/31 17:25
3F:→ vanchy: 感谢楼上^^原来是用错method 01/02 00:55