码迷,mamicode.com
首页 > 其他好文 > 详细

xpath获取带注释的text

时间:2019-02-28 14:34:55      阅读:400      评论:0      收藏:0      [点我收藏+]

标签:log   http   imp   html_   bit   nod   path   int   XML   


from lxml import etree

html_str = """
<div id="box1">this from blog.csdn.net/lncxydjq , DO NOT COPY!
<div id="box2">*****
<!--can u get me, bitch?-->
</div>
</div>
"""

html = etree.HTML(html_str)

print html.xpath(‘//div[@id="box1"]/div/node()‘)[1]
print type(html.xpath(‘//div[@id="box1"]/div/node()‘)[1])
print html.xpath(‘//div[@id="box1"]/div/node()‘)[1].text

"""output:
<!--can u get me, bitch?-->
<type ‘lxml.etree._Comment‘>
can u get me, bitch?



参考:https://blog.csdn.net/lncxydjq/article/details/77880824

xpath获取带注释的text

标签:log   http   imp   html_   bit   nod   path   int   XML   

原文地址:https://www.cnblogs.com/hankleo/p/10450019.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!