wordpress收费下载资源主题
wordpress付费下载资源插件

WordPress网站如何防止爬虫恶意抓取或采集

我们可以通过读取HTTP_USER_AGENT来判断请求,从而做到屏蔽页面抓取。

国内一些蜘蛛的UA:

$spiders = array(
'Googlebot',
'Baiduspider',
"Sogou web spider",
"360Spider",
"YisouSpider",
"Sosospider",
"YoudaoBot",
'Yahoo! Slurp',
'EasouSpider',
'bingbot'
);

模板兔给出大致的代码供参考:

$ua = $_SERVER['HTTP_USER_AGENT'];

//将恶意USER_AGENT存入数组

$now_ua = array('FeedDemon ','BOT/0.1 (BOT for JCE)','CrawlDaddy ','Java','Feedly','UniversalFeedParser','ApacheBench','Swiftbot','ZmEu','Indy Library','oBot','jaunty','YandexBot','AhrefsBot','MJ12bot','WinHttp','EasouSpider','HttpClient','Microsoft URL Control','YYSpider','jaunty','Python-urllib','lightDeckReports Bot');

//禁止空USER_AGENT,dedecms等主流采集程序都是空USER_AGENT,部分sql注入工具也是空USER_AGENT

if(!$ua) {
header("Content-type: text/html; charset=utf-8");

die('禁止爬取');

}else{
foreach($now_ua as $value ){

//判断是否是数组中存在的UA

if(strpos($ua,$value) !== false){
header("Content-type: text/html; charset=utf-8");

die('禁止爬取');

}
}

}

1 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请直接说明需求,勿问在否
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情