python中PyQuery库用法分享

2021-01-17 0 167

PyQuery库就是python中的一个解析库。作用十分强大,使用上也是相当的灵活,能够实现初始化字符串、初始化 HTML 文件、初始化请求响应等多种场景,另外,本身中的CSS选择器,也是经常被大家使用的对象,结合以上的大致内容总结,接下来,我们一起详细的了解使用内容。

安装:

>>> pip3 install pyquery

引用方法:

from pyquery import PyQuery as pq

CSS选择器:

from pyquery import PyQuery as pq
html = \'\'\'
<div id=\"container\">
<ul class=\"list\">
<li class=\"item-0\">first item</li>
<li class=\"item-1\"><a href=\"link2.html\" rel=\"external nofollow\" >second item</a></li>
<li class=\"item-0 active\"><a href=\"link3.html\" rel=\"external nofollow\" ><span class=\"bold\">third item</span></a></li>
<li class=\"item-1 active\"><a href=\"link4.html\" rel=\"external nofollow\" >fourth item</a></li>
<li class=\"item-0\"><a href=\"link5.html\" rel=\"external nofollow\" >fifth item</a></li>
</ul>
</div>
\'\'\'
doc=pq(html)
print(doc(\"#container .list li\"))

输出结果:

python中PyQuery库用法分享

到此这篇关于python中PyQuery库用法分享的文章就介绍到这了,更多相关python中PyQuery库是什么内容请搜索自学编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持自学编程网!

遇见资源网 Python python中PyQuery库用法分享 http://www.ox520.com/27856.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务