在进行网络数据抓取抓取时,使用requests可以直接处理json格式的返回结果,对于xml格式的返回结果requests并没有提供直接的支持。python内建了xml解析器,下面的示例说明两种情况下对xml的解析。
from xml.etree import ElementTree
xml_file = r'D:\BJMapSearch.xml'
try:
tree = ElementTree.parse(xml_file)
root = tree.getroot() # 获取根节点
except Exception, e: