Python 3.7.2 安装 lxml etree xml.etree.ElementTree
python --version Python 3.7.2 ?
pip install lxml==4.8.0
Collecting lxml==4.8.0
Downloading lxml-4.8.0-cp37-cp37m-win_amd64.whl (3.6 MB)
---------------------------------------- 3.6/3.6 MB 3.5 MB/s eta 0:00:00
Installing collected packages: lxml
Successfully installed lxml-4.8.0
try:
from lxml import etree
print("running with lxml.etree")
except ImportError:
try:
# Python 2.5
import xml.etree.cElementTree as etree
print("running with cElementTree on Python 2.5+")
except ImportError:
try:
# Python 2.5
import xml.etree.ElementTree as etree
print("running with ElementTree on Python 2.5+")
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree
print("running with cElementTree")
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree
print("running with ElementTree")
except ImportError:
print("Failed to import ElementTree from any known place")
root = etree.Element("root")
print(root.tag)
root.append( etree.Element("child1") )
child2 = etree.SubElement(root, "child2")
print(child2.tag)
print(etree.tostring(root, pretty_print=True))
|