爬虫和反爬的对抗一直在进行着… 为了帮助更好的进行爬虫行为以及反爬, 今天就来介绍一下网页开发者常用的反爬手段。

创新互联主营马鞍山网站建设的网络公司,主营网站建设方案,重庆App定制开发,马鞍山h5重庆小程序开发搭建,马鞍山网站营销推广欢迎马鞍山等地区企业咨询
1. BAN IP :网页的运维人员通过分析日志发现最近某一个IP访问量特别特别大,某一段时间内访问了无数次的网页,则运维人员判断此种访问行为并非正常人的行为,于是直接在服务器上封杀了此人IP。
解决方法:此种方法极其容易误伤其他正常用户,因为某一片区域的其他用户可能有着相同的IP,导致服务器少了许多正常用户的访问,所以一般运维人员不会通过此种方法来限制爬虫。不过面对许多大量的访问,服务器还是会偶尔把该IP放入黑名单,过一段时间再将其放出来,但我们可以通过分布式爬虫以及购买代理IP也能很好的解决,只不过爬虫的成本提高了。
2. BAN USERAGENT :很多的爬虫请求头就是默认的一些很明显的爬虫头python-requests/2.18.4,诸如此类,当运维人员发现携带有这类headers的数据包,直接拒绝访问,返回403错误
解决方法:直接r=requests.get(url,headers={'User-Agent':'Baiduspider'})把爬虫请求headers伪装成百度爬虫或者其他浏览器头就行了。
案例:雪球网
返回的就是
403
403 Forbidden.
Your IP Address: xxx.xxx.xxx.xxx .
但是当我们这样写:
返回的就是
200
< !DOCTYPE html>
3. BAN COOKIES :服务器对每一个访问网页的人都set-cookie,给其一个cookies,当该cookies访问超过某一个阀值时就BAN掉该COOKIE,过一段时间再放出来,当然一般爬虫都是不带COOKIE进行访问的,可是网页上有一部分内容如新浪微博是需要用户登录才能查看更多内容。
解决办法:控制访问速度,或者某些需要登录的如新浪微博,在某宝上买多个账号,生成多个cookies,在每一次访问时带上cookies
案例:蚂蜂窝
以前因为旅游的需求,所以想到了去抓一点游记来找找哪些地方好玩,于是去了蚂蜂窝网站找游记,一篇一篇的看真的很慢,想到不如把所有文章抓过来然后统计每个词出现的频率***,统计出最热的一些旅游景点,就写了一个scrapy爬虫抓游记,当修改了headers后开始爬取,发现访问过快服务器就会断开掉我的连接,然后过一段时间(几个小时)才能继续爬。于是放慢速度抓就发现不会再被BAN了。
4. 验证码验证 :当某一用户访问次数过多后,就自动让请求跳转到一个验证码页面,只有在输入正确的验证码之后才能继续访问网站
解决办法:python可以通过一些第三方库如(pytesser,PIL)来对验证码进行处理,识别出正确的验证码,复杂的验证码可以通过机器学习让爬虫自动识别复杂验证码,让程序自动识别验证码并自动输入验证码继续抓取
案例:安全客
当访问者对安全客访问过快他就会自动蹦出一个验证码界面。
如下:
5. javascript渲染 :网页开发者将重要信息放在网页中但不写入html标签中,而浏览器会自动渲染
基本
文件
流程
错误
SQL
调试
- 请求信息 : 2026-02-17 03:10:25 HTTP/1.1 GET : /article/djessed.html
- 运行时间 : 0.0677s ( Load:0.0032s Init:0.0005s Exec:0.0597s Template:0.0042s )
- 吞吐率 : 14.77req/s
- 内存开销 : 2,227.33 kb
- 查询信息 : 12 queries 5 writes
- 文件加载 : 36
- 缓存信息 : 0 gets 2 writes
- 配置加载 : 130
- 会话信息 : SESSION_ID=1vc22lkretqqr822hqr5a51t16
- /home/wwwroot/jxjierui.cn/index.php ( 1.12 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/ThinkPHP.php ( 4.61 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Think.class.php ( 12.26 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Storage.class.php ( 1.37 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Storage/Driver/File.class.php ( 3.52 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Mode/common.php ( 2.82 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Common/functions.php ( 53.56 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Hook.class.php ( 4.01 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/App.class.php ( 13.49 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Dispatcher.class.php ( 14.79 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Route.class.php ( 13.36 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Controller.class.php ( 11.23 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/View.class.php ( 7.59 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php ( 3.68 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php ( 3.88 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php ( 1.91 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Conf/convention.php ( 11.15 KB )
- /home/wwwroot/jxjierui.cn/App/Common/Conf/config.php ( 2.12 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Lang/zh-cn.php ( 2.55 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Conf/debug.php ( 1.48 KB )
- /home/wwwroot/jxjierui.cn/App/Home/Conf/config.php ( 0.32 KB )
- /home/wwwroot/jxjierui.cn/App/Home/Common/function.php ( 3.33 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php ( 5.62 KB )
- /home/wwwroot/jxjierui.cn/App/Home/Controller/ArticleController.class.php ( 6.11 KB )
- /home/wwwroot/jxjierui.cn/App/Home/Controller/CommController.class.php ( 1.60 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Model.class.php ( 60.11 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Db.class.php ( 32.43 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Db/Driver/Pdo.class.php ( 16.74 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Cache.class.php ( 3.83 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Cache/Driver/File.class.php ( 5.87 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Template.class.php ( 28.16 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Template/TagLib/Cx.class.php ( 22.40 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Template/TagLib.class.php ( 9.16 KB )
- /home/wwwroot/jxjierui.cn/App/Runtime/Cache/Home/7540f392f42b28b481b30614275e4e55.php ( 13.96 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php ( 0.97 KB )
- /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php ( 5.24 KB )
- [ app_init ] --START--
- Run Behavior\BuildLiteBehavior [ RunTime:0.000005s ]
- [ app_init ] --END-- [ RunTime:0.000023s ]
- [ app_begin ] --START--
- Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000147s ]
- [ app_begin ] --END-- [ RunTime:0.000158s ]
- [ view_parse ] --START--
- [ template_filter ] --START--
- Run Behavior\ContentReplaceBehavior [ RunTime:0.000048s ]
- [ template_filter ] --END-- [ RunTime:0.000065s ]
- Run Behavior\ParseTemplateBehavior [ RunTime:0.003306s ]
- [ view_parse ] --END-- [ RunTime:0.003320s ]
- [ view_filter ] --START--
- Run Behavior\WriteHtmlCacheBehavior [ RunTime:0.000075s ]
- [ view_filter ] --END-- [ RunTime:0.000084s ]
- [ app_end ] --START--
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`pid`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( pid= )
- [8] Undefined index: pid /home/wwwroot/jxjierui.cn/App/Home/Controller/ArticleController.class.php 第 47 行.
- [2] file_put_contents(./App/Runtime/Temp/b75ea7d9a585290bf6ac570a56b611e4.php): failed to open stream: Permission denied /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Cache/Driver/File.class.php 第 132 行.
- [8] Undefined index: db_host /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Db.class.php 第 120 行.
- [8] Undefined index: db_port /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Db.class.php 第 121 行.
- [8] Undefined index: db_name /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Db.class.php 第 122 行.
- [2] file_put_contents(./App/Runtime/Temp/ad9bd6a7b4a8d4a94032f07670910b4a.php): failed to open stream: Permission denied /home/wwwroot/jxjierui.cn/ThinkPHP/Library/Think/Cache/Driver/File.class.php 第 132 行.

0.0677s
