PHP判断是不是爬虫的方法详解编程语言

PHP判断是不是爬虫的方法
这个一般用于防止爬虫 和 seo优化(因为爬虫都是按照第一次打开显示的页面 有些ajax 等需要点击才能显示的就爬不到啦)


<?php
// 判断是否搜索引擎机器人访问
function isRobot() {
$agent= strtolower(isset($_SERVER['HTTP_USER_AGENT'])? $_SERVER['HTTP_USER_AGENT'] : '');
if(!empty($agent)){
$spiderSite= array(
"TencentTraveler",
"Baiduspider+",
"BaiduGame",
"Googlebot",
"msnbot",
"Sosospider+",
"Sogou web spider",
"ia_archiver",
"Yahoo! Slurp",
"YoudaoBot",
"Yahoo Slurp",
"MSNBot",
"Java (Often spam bot)",
"BaiDuSpider",
"Voila",
"Yandex bot",
"BSpider",
"twiceler",
"Sogou Spider",
"Speedy Spider",
"Google AdSense",
"Heritrix",
"Python-urllib",
"Alexa (IA Archiver)",
"Ask",
"Exabot",
"Custo",
"OutfoxBot/YodaoBot",
"yacy",
"SurveyBot",
"legs",
"lwp-trivial",
"Nutch",
"StackRambler",
"The web archive (IA Archiver)",
"Perl tool",
"MJ12bot",
"Netcraft",
"MSIECrawler",
"WGet tools",
"larbin",
"Fish search",
);
foreach($spiderSite as $val){
$str = strtolower($val);
if(strpos($agent, $str) !== false){
return true;
}
}
}

return false;
}
if(isRobot()){
echo'爬虫';
}else{
echo'不是爬虫';
}
?>

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/19091.html

(0)
上一篇 2021年7月19日 21:43
下一篇 2021年7月19日 21:43

相关推荐

发表回复

登录后才能评论