当新网站或网站的收集出现问题时,可能需要一个持续的搜索引擎蜘蛛来捕获环境。网站文章不收录的时候,是第一次查网站抓取日志,但是通过访问服务器查抓取日志有点麻烦。我们可以用代码把记录蜘蛛爬行日志的功能添加到
WordPress
网站!
1.WordPress
将以下代码复制到主题functions
.php
文件中。
// 记录蜘蛛访问记录 function
get_naps_bot
(){ $useragent
= strtolower
($_SERVER
['HTTP_USER_AGENT
']); if
(strpos
($useragent
, 'googlebot
') !== false
){ return
'Googlebot
'; } if
(strpos
($useragent
, 'msnbot
') !== false
){ return
'MSNbot
'; } if
(strpos
($useragent
, 'slurp
') !== false
){ return
'Yahoobot
'; } if
(strpos
($useragent
, 'baiduspider
') !== false
){ return
'Baiduspider
'; } if
(strpos
($useragent
, 'sohu
-search
') !== false
){ return
'Sohubot
'; } if
(strpos
($useragent
, 'lycos
') !== false
){ return
'Lycos
'; } if
(strpos
($useragent
, 'robozilla
') !== false
){ return
'Robozilla
'; } return
false
; } function
nowtime
(){ date_default_timezone_set
('Asia
/Shanghai
'); $date
=date
("Y
-m
-d
.G
:i
:s
"); return
$date
; } $searchbot
= get_naps_bot
(); if
($searchbot
) { $tlc_thispage
= addslashes
($_SERVER
['HTTP_USER_AGENT
']); $url
=$_SERVER
['HTTP_REFERER
']; $file
="robotslogs
.txt
"; $time
=nowtime
(); $data
=fopen
($file
,"a
"); $PR
="$_SERVER
[REQUEST_URI
]"; fwrite
($data
,"Time
:$time
robot
:$searchbot
URL
:$tlc_thispage
\n
page
:$PR
\r
\n
"); fclose
($data
); }
2.创建
robots
.txt
文件
- 在网站根目录下创建
robots
.txt
文件可写权限,最好是:777 或 755 权限!
在完成上面的步骤之后,查看蜘蛛日志
访问域名+robots
.txt
即可!https
://域名/robots
.txt
,例:https
://www
.huizhanii
.com
/robots
.txt
转载请注明:汇站网 » WordPress
搜索引擎蜘蛛步行记录代码