正在读取数据,页面载入中,请稍后...

禁止蜘蛛抓取站外链接,实现onclick链接加密的方法

关于这个onclick事件链接能加密,真的是一件很反常的事情,如果,没看到本文之前,你肯定会认为,谁吃饱了撑的没事干,谁闲得蛋疼才会这么做,其实,这是自己做不了,就讽刺别人也做不了,总的来说,就是给自己找找找借口。

关于禁止蜘蛛抓取外链的这件事,对nofollow标签和onclick标签里面的链接,蜘蛛是能够抓取到的,蜘蛛是能够抓取到链接的。这真的是伤害性不高,但它的侮辱性极强啊。要是你能把href标签给改了,那就是真的抓取不到了,你想要它抓取,它也抓取不到了。

就随便举个例子

<a hulahula="http://nikucms.com/" class="huala">小千博客</a>

或者改成这样

<a class="huala">小千博客</a>
<script type="text/javascript">
$('.huala').css({cursor:'pointer'}).on('click',function(){
  window.open('http://nikucms.com/','_blank');
});
</script>

要想蜘蛛抓取不了,类似于这种,没有href标签和onclick标签的,蜘蛛真的是不抓取的。关于蜘蛛,能抓取到data-original标签内的图片,这个还真的是个例外,因为,这种图片预加载,已成为主流,所以,蜘蛛才会识别这种标签。

蜘蛛能抓取到的

onclick="window.open('http://nikucms.com/','_self');"
onclick="window.open('http://nikucms.com/','_blank');"
onClick="window.open('http://nikucms.com/');"
<a rel="nofollow" href="http://nikucms.com/">小千个人博客</a>
<a rel="external" href="http://nikucms.com/">小千个人博客</a>
<a rel="noopener nofollow" href="http://nikucms.com/">小千个人博客</a>

对于蜘蛛来说,有时候,onClick标签确实不抓取的,不要信onClick标签和nofollow标签,能够屏蔽蜘蛛抓取,其实,蜘蛛是可以抓取到这个链接的。

onclick链接不加密

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
<title>全民博客</title>
</head>
<body>
<a style="cursor:pointer;" onclick="linka('http://nikucms.com/','_blank')">全民博客1</a>
<a style="cursor:pointer;" onclick="linka('http://baidu.com/','_blank')">全民博客2</a>
<a style="cursor:pointer;" onclick="linka('http://toutiao.com/','_blank')">全民博客3</a>
<a style="cursor:pointer;" onclick="linka('http://biying.com/','_blank')">全民博客4</a>
<a style="cursor:pointer;" onclick="linka('http://nidecms.com/','_self')">全民博客5</a>
<script type="text/javascript">
function linka(hrsrc,fblank){
    var href = hrsrc;
    window.open(href,fblank);
}
</script>
</body>
</html>

看代码,其实,这种onclick链接不加密,和上面,直接写onclick事件链接,效果是一样的,我只是为了展示下,加密之前和加密之后的区别,下面上加密之后的代码。

onclick链接加密

<?php 
error_reporting(0);
header('Content-type:text/html;charset=utf-8');
function enjs($_play) {
	$schwhere = '';
	$schwhere.= cape($_play);
	return base64_encode(ltrim($schwhere,'&'));
}
function cape($string, $in_encoding = 'UTF-8',$out_encoding = 'UCS-2') {
	$return = '';
	if (function_exists('mb_get_info')) {
		for ($x = 0; $x < mb_strlen ( $string, $in_encoding ); $x ++) {
			$str = mb_substr ( $string, $x, 1, $in_encoding );
			if (strlen ( $str ) > 1) {
				$return .= '%u' . strtoupper ( bin2hex ( mb_convert_encoding ( $str, $out_encoding, $in_encoding ) ) );
			} else {
				$return .= '%' . strtoupper ( bin2hex ( $str ) );
			}
		}
	}
	return $return;
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
<title>全民博客</title>
</head>
<body>
<a style="cursor:pointer;" onclick="linka(&#39;<?php echo enjs('http://nikucms.com/'); ?>&#39;,'_blank')">全民博客1</a>
<a style="cursor:pointer;" onclick="linka(&#39;<?php echo enjs('https://www.toutiao.com/'); ?>&#39;,'_blank')">全民博客2</a>
<a style="cursor:pointer;" onclick="linka(&#39;<?php echo enjs('https://www.baidu.com/'); ?>&#39;,'_blank')">全民博客3</a>
<a style="cursor:pointer;" onclick="linka(&#39;<?php echo enjs('https://cn.bing.com/'); ?>&#39;,'_blank')">全民博客4</a>
<a style="cursor:pointer;" onclick="linka(&#39;<?php echo enjs('http://nidecms.com/'); ?>&#39;,'_self')">全民博客5</a>
<script type="text/javascript">
var Base64={_2:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._12(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._2.charAt(s)+this._2.charAt(o)+this._2.charAt(u)+this._2.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9+/=]/g,"");while(f<e.length){s=this._2.indexOf(e.charAt(f++));o=this._2.indexOf(e.charAt(f++));u=this._2.indexOf(e.charAt(f++));a=this._2.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._11(t);return t},_12:function(e){e=e.replace(/rn/g,"n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_11:function(e){var t="";var n=0;var r=c1=c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}};

function linka(hrsrc,fblank){
    var jscode = Base64.decode(hrsrc);
    var srcode = unescape(jscode);
	var href = srcode;
	//console.log(url);
    window.open(href,fblank);
}
</script>
</body>
</html>

呵呵,看完这个代码,是不是有点想忍不住发笑啊。哎,要是你觉得开心,你就笑话我吧。这种是看起来觉得高大尚,但是你有没有发现。把JS抛开不要,都是onclick事件的话,和下面的这几句代码,这个效果不就是一样的嘛。

onclick="window.location.href='http://nikucms.com/';"
onclick="window.open('http://nikucms.com/','_self');"
onclick="window.open('http://nikucms.com/','_blank');"
onClick="window.open('http://nikucms.com/');"

看起来很高端

忙活了半天,发现这个代码,算是白忙活了。像这种直接用window.open(链接)的形式,这种是不支持加密链接的,你要是把链接一加密,一转换,链接访问就错误了。但是,上面改了的那种代码,是支持链接加密的,哎,忙活了半天,总算是没白忙活啊,小千真的是,把代码玩出了新高度啊。

只能忽悠小白

禁止蜘蛛抓取站外链接,实现onclick链接加密的方法 - 全民博客

像onclick="linka('链接','_blank')"这种点击事件,花了半个小时写出来代码,看起来毫无用处,唯一的作用,但是这个链接可以加密啊。可以转成你想转换的链接加密格式,多放点垃圾代码,然后再字符过滤,这样就完全看不出来真正的链接了,作为混淆链接代码,忽悠小白还是有点作用的。

本文结束

评论专区

发表评论

评论列表(无评论)