The search engine crawlers can access websites by capturing pages remotely. we cannot use JS code to obtain the Agent information of the spider, but we can use the image tag so that we can
The search engine crawlers access websites by capturing pages remotely. we cannot use JS code to obtain the Agent information of the spider, but we can use the image tag, in this way, we can obtain the agent data of the Spider. by analyzing the agent data, we can determine the types, gender, and other factors of the spider, we can record statistics through databases or text.
Database structure:
- #
- # Table structure 'Naps _ stats_bot'
- #
-
- Create table 'Naps _ stats_bot '(
- 'Botid' int (10) unsigned not null auto_increment,
- 'Botname' varchar (100) not null default '',
- 'Botagent' varchar (200) not null default '',
- 'Bottag' varchar (100) not null default '',
- 'Botcount' int (11) not null default '0 ',
- 'Botlast 'datetime not null default '2017-00-00 00:00:00 ',
- 'Botlasturl' varchar (250) not null default '',
- Unique key 'botid' ('botid '),
- KEY 'botname' ('botname ')
- ) TYPE = MyISAM AUTO_INCREMENT = 9;
-
- #
- # Export the table data 'Naps _ stats_bot'
- #
-
- Insert into 'Naps _ stats_bot 'VALUES (1, 'googlebot', 'googlebot/2.X (http://www.googlebot.com/bot.html) ', 'googlebot', 0, '2017-00-00 00:00:00 ', '');
- Insert into 'Naps _ stats_bot 'VALUES (2, 'msnbot', 'msnbot/0.1 (http://search.msn.com/msnbot.htm) ', 'msnbot', 0, '2017-00-00 00:00:00 ', '');
- Insert into 'Naps _ stats_bot 'VALUES (3, 'inktomi slurp', 'slurp/123456', 'slurp', 0, '2017-00-00 00:00:00 ', '');
- Insert into 'Naps _ stats_bot 'VALUES (4, 'baidider Ider', 'baidider Ider (http://www.baidu.com/search/spider.htm) ', 'baidider Ider', 0, '2017-00-00 00:00:00 ', '');
- Insert into 'Naps _ stats_bot 'VALUES (5, 'yahoobot', 'mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp) ', 'slurp', 0, '2017-00-00 00:00:00 ','');
- Insert into 'Naps _ stats_bot 'VALUES (6, 'sohubot', 'sohu-search', 'sohu-search', 0, '2017-00-00 00:00:00 ', '');
- Insert into 'Naps _ stats_bot 'VALUES (7, 'lycos', 'lycos/x. x', 'lycos ', 0, '2017-00-00 00:00:00 ','');
- Insert into 'Naps _ stats_bot 'VALUES (8, 'robozilla', 'robozilla/123456', 'robozilla ', 0, '2017-00-00 00:00:00 ','');
PHP program:
- Error_reporting (E_ALL &~ E_NOTICE );
-
- Function get_naps_bot ()
- {
- $ Useragent = strtolower ($ _ SERVER ['http _ USER_AGENT ']);
-
- If (strpos ($ useragent, 'googlebot ')! = False ){
- Return 'bot bot ';
- }
-
- If (strpos ($ useragent, 'msnbot ')! = False ){
- Return 'msnbot ';
- }
-
- If (strpos ($ useragent, 'slurp ')! = False ){
- Return 'yahoobot ';
- }
-
- If (strpos ($ useragent, 'baidider Ider ')! = False ){
- Return 'baidider Ider ';
- }
-
- If (strpos ($ useragent, 'sohu-search ')! = False ){
- Return 'sohubot ';
- }
-
- If (strpos ($ useragent, 'lycos ')! = False ){
- Return 'lycos ';
- }
-
- If (strpos ($ useragent, 'robozilla ')! = False ){
- Return 'robozilla ';
- }
- Return false;
- }
- $ Tlc_thispage = addslashes ($ _ SERVER ['http _ USER_AGENT ']);
- // Add a crawler record
- $ Searchbot = get_naps_bot ();
- If ($ searchbot ){
- $ DB_naps-> query ("UPDATE naps_stats_bot SET botcount = botcount 1, botlast = NOW (), botlasturl = '$ tlc_thispage' WHERE botname = '$ searchbot '");
- }
- ?>