Python爬虫PyQuery库基本用法入门教程
来源:
中文源码网 浏览:360 次 日期:2024-04-25 04:12:16
【下载文档: Python爬虫PyQuery库基本用法入门教程.txt 】
Python爬虫PyQuery库基本用法入门教程
本文实例讲述了Python爬虫PyQuery库基本用法。分享给大家供大家参考,具体如下:
PyQuery库也是一个非常强大又灵活的网页解析库,如果你有前端开发经验的,都应该接触过jQuery,那么PyQuery就是你非常绝佳的选择,PyQuery 是 Python 仿照 jQuery 的严格实现。语法与 jQuery 几乎完全相同,所以不用再去费心去记一些奇怪的方法了。
官网地址:http://pyquery.readthedocs.io/en/latest/
jQuery参考文档: http://jquery.cuishifeng.cn/
1、字符串的初始化
from pyquery import PyQuery as pq
html = '''
'''
doc = pq(html)
print(doc)
print(type(doc))
print(doc('li'))
first item
second item
third item
fourth item
fifth item
2、打开html文件
注意路劲问题
from pyquery import PyQuery as pq
doc = pq(filename='index.html')
print(doc)
print(doc('head'))
Title
'''