python的lxml模块的xpath的使用

本文共有364个字,关键词:

问题:python的lxml模块的xpath如何使用
解决:示例
方法:
from lxml import html
tree = html.fromstring('''
<div class="content">
<h1>《Python模块》</h1>
<p>python的lxml模块的介绍</p>
<p>lxml模块的xpath如何使用</p>
<p>lxml模块的fromstring的使用</p>
</div>
''')
for p in tree.xpath("//div/p"):    # 匹配div下p标签
print(p.tag)
print(p.text)

参考:http://blog.csdn.net/heavyzero/article/details/44452337

版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论