zanysoft/laravel-crawler-detect

一个通过用户代理检测网络爬虫的Laravel包

1.0 2020-09-18 21:31 UTC

This package is auto-updated.

Last update: 2024-09-16 09:52:10 UTC


README

Build Status Total Downloads Scrutinizer Code Quality StyleCI

安装

运行 composer require zanysoft/laravel-crawler-detect 或在您的 composer.json 文件中添加 "zanysoft/laravel-crawler-detect": "^1.0"

将以下内容添加到您的 config/app.php 文件中的 providers 数组中..

  ZanySoft\LaravelCrawlerDetect\LaravelCrawlerDetectServiceProvider::class,

...并将以下内容添加到您的 aliases 数组...

  'Crawler'   => 'ZanySoft\LaravelCrawlerDetect\Facades\LaravelCrawler',

Laravel 5.5 使用包自动发现功能,因此不需要您手动添加 ServiceProvider。

用法

// Check current 'visitors' user agent
if(Crawler::isCrawler()) {
  // true if crawler user agent detected
}


// Pass a user agent as a string
if(Crawler::isCrawler('Mozilla/5.0 (compatible; aiHitBot/2.9; +https://www.aihitdata.com/about)')) {
  // true if crawler user agent detected
}