金狮镖局 Design By www.egabc.com

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库

金狮镖局 Design By www.egabc.com
金狮镖局 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金狮镖局 Design By www.egabc.com

评论“python中PyQuery库用法分享”

暂无python中PyQuery库用法分享的评论...