• 技术文章 >Python技术 >Python基础教程

    python中PyQuery库是什么?

    十一十一2021-03-04 09:50:16原创3857

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    安装:

    1

    >>> pip3 install pyquery

    引用方法:

    1

    from pyquery import PyQuery as pq

    CSS选择器:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    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">second item</a></li>

    <li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li>

    <li class="item-1 active"><a href="link4.html">fourth item</a></li>

    <li class="item-0"><a href="link5.html">fifth item</a></li>

    </ul>

    </div>

    '''

    doc=pq(html)

    print(doc("#container .list li"))

    输出结果:

    好啦,以上就是PyQuery库的全部使用方式了,感兴趣的小伙伴可以多了解学习下哦~

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:pyquery库
    上一篇:python cutecharts库如何使用? 下一篇:python中pdb模块怎么用?

    相关文章推荐

    • 如何使用python制作抽奖程序?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网