网络爬虫的(按)尺寸(划分)
- 爬取网页,玩转网页,小规模,爬取速度不敏感,Requests库
- 爬取网站,系列网站,中规模,爬取速度敏感,Scrapy库
- 爬取全网,大规模,搜索引擎,爬取速度关键,定制开发
网络爬虫可能引发的问题
网络爬虫的“骚扰”
受限于编写水平和目的,网络爬虫将会为web服务器带来巨大的资源开销。
网络爬虫的法律风险
服务器上的数据有产权归属
网络爬虫获取数据后牟利将带来法律风险
网络爬虫泄露隐私
网络爬虫可能具备突破简单访问控制的能力,获得被保护数据从而泄露个人隐私。
网络爬虫的限制
来源审查:判断User-Agent进行限制
检查来访HTTP协议头的User-Agent域,只相应浏览器或友好爬虫的访问
发布公告:Robots协议
告知所有爬虫网站的爬取策略,要求爬虫遵守。
Robots协议
Robots Exclusion Standard 网络爬虫排除标准
作用:网站告知网络爬虫那些页面可以抓取,哪些不行。
形式:在网站根目录下的robots.txt文件
User-agent: *
Disallow: /?*
Disallow: /pop/*.html
Disallow: /pinpai/*.html?*
User-agent: EtaoSpider
Disallow: /
User-agent: HuihuiSpider
Disallow: /
User-agent: GwdangSpider
Disallow: /
User-agent: WochachaSpider
Disallow: /
后四种爬虫被京东认为是恶意爬虫,拒绝这四种爬虫的访问
案例:京东的Robots协议
- http://www.baidu.com/robots.txt
- http://news.sina.com.cn/robots.txt
- http://www.qq.com/robots.txt
- http://news.qq.com/robots.txt
- http://www.moe.edu.cn/robots.txt (无robots协议)
注意:robots协议一定是放在网站的根目录下
Robots协议的使用
网络爬虫:自动或人工识别robots.txt,再进行内容爬取
约束性:Robots协议是建议单非约束性,网络爬虫可以不遵守,但存在法律风险。
访问量特别小可以不遵守robots协议