首页 > 编程语言 > 详细

python lxml 使用

时间:2018-01-03 13:06:24      阅读:198      评论:0      收藏:0      [点我收藏+]
>>> import lxml.html
>>> broken_html=‘<ul class=country><li>Area<li>Population</ul>‘
>>> tree=lxml.html.fromstring(broken_html) #parse the HTML
>>> fixed_html=lxml.html.tostring(tree,pretty_print=True)
>>> print fixed_html
<ul class="country">
<li>Area</li>
<li>Population</li>
</ul>

>>> li=tree.cssselect(‘ul.country > li‘)[0]
>>> area=li.text_content()
>>> print area
Area
>>> 

  

python lxml 使用

原文:https://www.cnblogs.com/royfans/p/8183169.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!