用户登录
用户注册

分享至

python中PyQuery库用法分享

  • 作者: c_hongbin
  • 来源: 51数据库
  • 2021-09-02

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  rel="external nofollow" >second item</a></li>
<li class="item-0 active"><a  rel="external nofollow" ><span class="bold">third item</span></a></li>
<li class="item-1 active"><a  rel="external nofollow" >fourth item</a></li>
<li class="item-0"><a  rel="external nofollow" >fifth item</a></li>
</ul>
</div>
'''
doc=pq(html)
print(doc("#container .list li"))

输出结果:

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

软件
前端设计
程序设计
Java相关