python中PyQuery库用法分享

作者:十一 时间:2023-12-05 03:08:31 

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库用法分享

来源:https://www.py.cn/jishu/jichu/22973.html

标签:python,PyQuery库
0
投稿

猜你喜欢

  • 利用Matplotlib实现单画布绘制多个子图

    2021-10-30 19:33:58
  • 使用python实现希尔、计数、基数基础排序的代码

    2023-07-12 09:02:24
  • Python基础之hashlib模块subprocess模块logging模块

    2022-08-12 02:45:52
  • SQL Server中的XML数据类型详解

    2024-01-15 20:56:44
  • 使用Python对接OpenAi API实现智能QQ机器人的方法

    2023-08-12 10:24:25
  • python实现图像拼接

    2023-07-26 15:38:27
  • python isinstance函数用法详解

    2023-05-08 12:43:56
  • Python实现企业微信机器人每天定时发消息实例

    2023-09-04 22:08:40
  • 详解监听MySQL的binlog日志工具分析:Canal

    2024-01-27 11:00:35
  • 详解Laravel模型事件和模型事件在Trait中的使用

    2023-06-17 17:19:28
  • 在Ubuntu或Debian系统的服务器上卸载MySQL的方法

    2024-01-25 17:24:55
  • TensorFlow安装及jupyter notebook配置方法

    2022-09-11 01:05:23
  • python getopt 参数处理小示例

    2021-03-02 13:05:02
  • thinkphp利用模型通用数据编辑添加和删除的实例代码

    2024-05-03 15:13:14
  • Golang利用channel协调协程的方法详解

    2024-05-08 10:21:54
  • 在ASP.NET 2.0中操作数据之五十二:使用FileUpload上传文件

    2023-07-07 04:19:18
  • 对python插入数据库和生成插入sql的示例讲解

    2022-03-10 05:46:40
  • Python使用time模块实现指定时间触发器示例

    2022-05-13 02:57:59
  • 关于利用:first-letter实现首字下沉的一些看法

    2010-04-20 17:19:00
  • python3+PyQt5实现自定义窗口部件Counters

    2021-05-21 10:47:47
  • asp之家 网络编程 m.aspxhome.com