vipx / bot-detect
机器人检测库
v2.1.0
2022-04-01 04:08 UTC
Requires
- php: >=7.4
- symfony/config: ^5.0
- symfony/yaml: ^5.0
Requires (Dev)
- phpunit/phpunit: ^9.0
README
此库可以帮助您检测像Google、Yahoo或Bing这样的机器人。
使用 composer 进行安装
$ php composer.phar require vipx/bot-detect
使用方法
use Vipx\BotDetect\BotDetector; use Symfony\Component\Config\FileLocator; use Vipx\BotDetect\Metadata\Loader\YamlFileLoader; # Instantiate Symfony components required to load and parse YAML files. $locator = new FileLocator(); $loader = new YamlFileLoader($locator); # Use extended bot list prodivded in Resources directory. $metadataFile = './Resources/metadata/extended.yml'; # Instantiate a BotDetector with the YamlFileLoader instance and path to YAML. $detector = new BotDetector($loader, $metadataFile); # Call detect() on BotDetector, passing in a user agent string and IP address, # most commonly found in $_SERVER['HTTP_USER_AGENT'] and $_SERVER['REMOTE_ADDR'] # respectively. # detect() will return a Vipx\BotDetect\Metadata\Metadata object containing the # details of a matched bot and null on no match. $bot = $detector->detect($agent, $ip);
注意:为了极大地提高性能,BotDetector
内置缓存,可用于加速解析和加载元数据。
# Instantiate a BotDetector with additional options. $detector = new BotDetector($loader, $metadataFile, [ 'debug' => $debug, 'cache_dir' => '/acme/cache', ]);
通过附加选项 metadata_cache_file
和 metadata_dumper_class
,您可以进一步控制缓存文件的命名或生成方式。
待办事项
- 添加额外的元数据加载器(xml, php)
- 用从外部存档动态添加的数据替换静态固定值,例如使用某种公共API或其他存储库中的数据,例如GitHub或Bitbucket
致谢
机器人列表的第一个版本来自phpBB社区创建的Manage_Bots
脚本。以下社区成员和贡献者参与了脚本及其机器人列表的工作
phpBB 社区
Marcus Wendel,ReptileGuy,Young Jedi Knight,Pony99CA,Clava,ricjonhay,roBBx,Sr X,HGN,AmigoJack,millipede,maxwell2,StandBy,ade74,heredia21,TheSnake,natalia26,Puchahawa,T50,Peter77sx,Schwpz,Vinny,lanesharon,leschek,fac7orx,Joshua203,Paul,doktornotor,stokerpiller 以及 raimon
贡献者
COil,jdeniau,rubenrua,smilesrg,jbboehr
如果您发现了一个或多个缺失的机器人,只需简单地将此仓库进行分叉,并将它们添加到合适的 元数据文件 中。