作家
登录

Python爬虫神器PyQuery的使用方法

作者: 来源: 2017-05-31 09:47:11 阅读 我要评论

<a href=http://developer.51cto.com/art/201705/"link2.html">second item</a> 
  •  
  • <a href=http://developer.51cto.com/art/201705/"link3.html"><span class="bold">third item</span></a> 
  •  
  • <a href=http://developer.51cto.com/art/201705/"link4.html">fourth item</a> 
  •  
  • <a href=http://developer.51cto.com/art/201705/"link5.html">fifth item</a> 
  •  
  • <li class="item-0">first item</li> 
  •  
  • <li class="item-1"><a href=http://developer.51cto.com/art/201705/"link2.html">second item</a></li> 
  •  
  • <li class="item-0 active"><a href=http://developer.51cto.com/art/201705/"link3.html"><span class="bold">third item</span></a></li> 
  •  
  • <li class="item-1 active"><a href=http://developer.51cto.com/art/201705/"link4.html">fourth item</a></li> 
  •  
  • <li class="item-0"><a href=http://developer.51cto.com/art/201705/"link5.html">fifth item</a></li>  
  • 不过最常用的┞氛样 items 办法

    网页请求

    PyQuery 本身还有网页请求功能,并且会把请求下来的网页代码转为 PyQuery 对象。

    1. from pyquery import PyQuery as pq 
    2.  
    3. print pq('http://cuiqingcai.com/', headers={'user-agent''pyquery'}) 
    4.  
    5. print pq('http://httpbin.org/post', {'foo''bar'}, method='post', verify=True 

    感触感染一下,GET,POST,样样通。

    Ajax

    PyQuery 同样支撑 Ajax 操作,带有 get 和 post 办法,不过不常用,一般我们不会用 PyQuery 来做收集请求,仅仅是用来解析。

    PyQueryAjax

    API

    最后少不了的,API大年夜放送。

    API (https://pythonhosted.org/pyquery/api.html)

    原汁原味最全的API,都在琅绫擎了!如不雅你对 jQuery 语法不熟,强烈建议先进修下 jQuery,再回来看 PyQuery,你会认为异常亲切!

    然而比比 PyQuery,哦我的确太爱它了!

    结语

    用完了 PyQuery,我已经深深爱上了他!

    你呢?

    【编辑推荐】

    1. Python爬虫爬取知乎小结
    2. 深刻Python列表的内部实现
    3. 应用Python供给高机能计算办事
    4. 深刻懂得GIL:若何写出高机能及线程安然的Python代码
    5. Python算法拭魅战系列:栈
    【义务编辑:枯木 TEL:(010)68476606】

      推荐阅读

      OTT IPTV商机广阔 运营商如何进一步发掘CDN机会窗口

    在此前4月份的亚太CDN峰会上,中国联通收集技巧研究院、高等工程师乔治曾做过一个猜测:全球流量复合增长率占>>>详细阅读


    本文标题:Python爬虫神器PyQuery的使用方法

    地址:http://www.17bianji.com/lsqh/35490.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)