使用nginx的自带功能
通过对httpuseragent阻塞来实现,包括GET/POST方式的请求,以nginx为例。
拒绝以wget方式的httpuseragent,增加如下内容:
Block http user agent - wgetif ($http_user_agent ~* (Wget) ) { return 403;}
如何拒绝多种httpuseragent,内容如下:
if ($http_user_agent ~ (agent1|agent2|Foo|Wget|Catall Spider|AcoiRobot) ) { return 403;}
限制User-Agent字段
User-Agent字段能识别用户所使用的操作系统、版本、CPU、浏览器等信息,如果请求来自非浏览器,就能识别其为爬虫,阻止爬虫抓取网站信息。
限制IP或账号
根据业务需求,要求用户通过验证码后才能使用某些功能或权限。当同一IP、同一设备在一定时间内访问网站的次数,系统自动限制其访问浏览。只有在输入正确的验证码之后才能继续访问。
验证码拦截
在登录页等页面,添加验证码,以识别是正常流量还是恶意爬虫,也是一种基本的操作。

HTMl代码如下:
<script src="captcha.js?appid=xxx"></script>
<script>
kg.captcha({
// 绑定元素,验证框显示区域
bind: "#captchaBox3",
// 验证成功事务处理
success: function(e) {
console.log(e);
document.getElementById('kgCaptchaToken').value = e['token']
},
// 验证失败事务处理
failure: function(e) {
console.log(e);
},
// 点击刷新按钮时触发
refresh: function(e) {
console.log(e);
}
});
</script>
<div id="captchaBox3">载入中 ...</div>
<input type="hidden" name="kgCaptchaToken" value="" />
通过对httpuseragent阻塞来实现,包括GET/POST方式的请求,以nginx为例。
拒绝以wget方式的httpuseragent,增加如下内容:
Block http user agent - wgetif ($http_user_agent ~* (Wget) ) { return 403;}
如何拒绝多种httpuseragent,内容如下:
if ($http_user_agent ~ (agent1|agent2|Foo|Wget|Catall Spider|AcoiRobot) ) { return 403;}
限制User-Agent字段
User-Agent字段能识别用户所使用的操作系统、版本、CPU、浏览器等信息,如果请求来自非浏览器,就能识别其为爬虫,阻止爬虫抓取网站信息。
限制IP或账号
根据业务需求,要求用户通过验证码后才能使用某些功能或权限。当同一IP、同一设备在一定时间内访问网站的次数,系统自动限制其访问浏览。只有在输入正确的验证码之后才能继续访问。
验证码拦截
在登录页等页面,添加验证码,以识别是正常流量还是恶意爬虫,也是一种基本的操作。

HTMl代码如下:
<script src="captcha.js?appid=xxx"></script>
<script>
kg.captcha({
// 绑定元素,验证框显示区域
bind: "#captchaBox3",
// 验证成功事务处理
success: function(e) {
console.log(e);
document.getElementById('kgCaptchaToken').value = e['token']
},
// 验证失败事务处理
failure: function(e) {
console.log(e);
},
// 点击刷新按钮时触发
refresh: function(e) {
console.log(e);
}
});
</script>
<div id="captchaBox3">载入中 ...</div>
<input type="hidden" name="kgCaptchaToken" value="" />