安装:(对python3.6)
pip install beautifulsoup4
pip install lxml==4.1.1
from bs4 import BeautifulSoup
path = 'E:\VOCdevkit\VOC2012\Annotations/2007_000027.xml'
a= BeautifulSoup(open(path),"lxml")
print(a.prettify())#按照标准的缩进格式输出获取的soup内容
print(a.size.width.name)#获取size标签里width标签名
for i in a.size.contents:#循环size标签里的子标签
if i.name:
print('{}:'.format(i.name),i.string)#i.string获取i标签里的内容