Python爬虫-PyQuery
一些看法
关于数据提取的四个主流方法就回顾完了,当然不用也不必全会。我个人认为正则是一定要OK的,其余三个拣一个上手即可。剩下部分,总得达到“开书了然”的境界吧。毕竟说不定什么时候就需要阅览别人的代码,你怎么管得找人家用xpath呢还是用PyQuery呢?
这是最后一次在句子迷实战,此次目标书籍:《年华是无效信》——是我钟爱!
使用
from pyquery import PyQuery as pq
doc = pq(html)
语法
初始化
- 除了直接初始化拿到的网页,还可以有以下两种方法
a.pq(url="")
直接获取网页(不建议,没有隐藏爬虫信息吧)
b.pq(filename="")
针对本地文件
<html><head><title>The Dormouse's story</title>title></head>head>
<body>
<p class="title"><b>The Dormouse's story</b>b></p>p>
<p class="story">Once upon a time there were three little sisters; and their names were
<