美文网首页
Python3.7安装lxml没有etree问题解决

Python3.7安装lxml没有etree问题解决

作者: 8a8d7f2e842b | 来源:发表于2019-12-07 22:25 被阅读0次

1. 安装Python3.7环境以后用pip下载lxml4.4.1

pip install lxml==4.4.4

2. 在Python文件中使用方式:

<!-- hello.html -->

<div>
    <ul>
         <li class="item-0"><a href="link1.html">first item</a></li>
         <li class="item-1"><a href="link2.html">second item</a></li>
         <li class="item-inactive"><a href="link3.html"><span class="bold">third item</span></a></li>
         <li class="item-1"><a href="link4.html">fourth item</a></li>
         <li class="item-0"><a href="link5.html">fifth item</a></li>
     </ul>
 </div>
from lxml import html

etree = html.etree
html = etree.parse('./hello.html')
result = etree.tostring(html, pretty_print=True)
print(result.decode('utf-8'))

相关文章

网友评论

      本文标题:Python3.7安装lxml没有etree问题解决

      本文链接:https://www.haomeiwen.com/subject/tmdpgctx.html