- etree.parse直接接受一个文档,按照文档结构解析(本地文件)
import xml.etree.elementtree as et
tree = et.parse('country_data.xml')
root = tree.getroot()
- etree.html可以解析html文件:(服务器上返回的html数据)
page = etree.html(html.lower().decode('utf-8'))
hrefs = page.xpath(u"//a")
for href in hrefs:
print href.attrib