使用python的beautifulsoup读取xml配置文件

2025-02-26 07:18:48
推荐回答(2个)
回答1:

beautifulsoup分析html非常方便,但xml却不怎么样

推荐使用自带的xml的etree分析

import xml.etree.ElementTree as ET
root = ET.fromstring('''''')
root[0].items()

回答2:

# coding:utf8
from BeautifulSoup import BeautifulSoup
axml = '''



'''
soup = BeautifulSoup(axml)
for s in soup.findAll('dd',{'key':"d1"}):
print s.get('value').encode('utf8')

运行结果:

大一

[Finished in 0.1s]