先用语法搜索一波想要爬取的网站
点击页码,抓包看看请求头,多抓几个放入对比器找到页码参数
可以看到页码参数为pn,第一页为0,第二页为10,第五页为40,可以知道每一页pn增加10,写python脚本。
import re
from bs4 import BeautifulSoup as BS
import HackRequests as hack
def tomcat(raw):
hh = hack.httpraw(raw=raw)
soup = BS(hh.text(), features="html.parser")
#正则匹配网址,通过观察,a标签,href属性格式
links = soup.findAll(name='a', attrs={'href': re.compile('http://www.baidu.com/link\?u