crawler-04 网络爬虫安全问题

crawler-04 网络爬虫安全问题

  网络爬虫,盗亦有道。网络爬虫带来的问题很多,因此有很多反对网络爬虫的声音。

一、网络爬虫引发的问题

1)性能骚扰

  网站服务器默认只接受人类访问,而爬虫爬取资源的速度是人类访问资源的千百倍,消耗了大量的服务器资源。当然,如果对爬取速度和行为在代码上做限制,使得爬虫变成类人行为,即可减少和避免此类问题;

2)法律风险

  服务器上的数据有产权归属,网络爬虫获取数据后牟利将带来法律风险;

3)隐私泄露

  网络爬虫可能具备突破简单访问控制的能力,获得被保护数据 从而泄露个人隐私;

二、网络爬虫的尺寸

  大部分的网络爬虫(>90%),都是小规模爬虫,如下图。

1Ea7xx.png

三、网络爬虫和的限制

1)来源审查:判断User‐Agent进行限制(技术层面限制)
  检查来访HTTP协议头的User‐Agent域,只响应浏览器或友好爬虫的访问;
2)发布公告:Robots协议(道德层面限制)
  告知所有爬虫网站的爬取策略,要求爬虫遵守;

四、Robots协议

  Robots协议(Robots Exclusion Standard,网络爬虫排除标准)
1)作用:网站告知网络爬虫哪些页面可以抓取,哪些不行;

2)形式:在网站根目录下的robots.txt文件;

3)举例:京东的robots协议:https://www.jd.com/robots.txt

1
2
3
4
5
6
7
8
9
10
11
12
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: /

基本语法解析:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1)*代表所有,/代表根目录 
2)User-agent指明哪些爬虫;Disallow代表不允许访问的路径
3)任何爬虫不允许访问根目录下以问号开头的路径;以及符合/pop/*.html的路径;以及符合/pinpai/*.html?* 的路径;
User-agent: *
Disallow: /?*
Disallow: /pop/*.html
Disallow: /pinpai/*.html?*
4)拒绝EtaoSpider网络爬虫爬取京东的任何资源;
User-agent: EtaoSpider
Disallow: /
5)同理,拒绝下面三个网络爬虫爬取京东的任何资源;
User-agent: HuihuiSpider
Disallow: /
User-agent: GwdangSpider
Disallow: /
User-agent: WochachaSpider
Disallow: /

4)其他robots协议

  注意,www.qq.com和news.qq.com二者的robots协议是不一样的;同时,并不是所有网站都是有robots协议的。

1
2
3
4
5
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协议)

5)注意事项

  robots协议规定,如果一个网站不提供robots.txt文件,那么默认允许所有爬虫无限制地爬取其内容;

五、Rrobots协议的遵守方式

1)网络爬虫:自动或人工识别robots.txt,再进行内容爬取;

2)约束性:Robots协议是建议但非约束性,网络爬虫可以不遵守,但存在法律风险;

3)对于任何网络爬虫,法律、道德层面上,都应该遵守Robots协议;

4)类人行为可不参考Robots协议!

UTOOLS1576466536048.png

欢迎打赏,谢谢
------ 本文结束------
0%