Skip to content

Instantly share code, notes, and snippets.

@lord-alfred
Last active June 30, 2019 20:16
Show Gist options
  • Save lord-alfred/e45ff2e9e3e50c46588b7cf69db4e73d to your computer and use it in GitHub Desktop.
Save lord-alfred/e45ff2e9e3e50c46588b7cf69db4e73d to your computer and use it in GitHub Desktop.
- regex: 'Embedly/0\.\d+'
name: 'Embedly'
category: 'Crawler'
url: 'http://support.embed.ly/'
- regex: 'BrandVerity/1\.0'
name: 'BrandVerity'
category: 'Crawler'
url: 'https://www.brandverity.com/why-is-brandverity-visiting-me'
<?php
namespace App\Utils;
use DeviceDetector\Parser\Bot;
use DeviceDetector\DeviceDetector as DeviceDetectorBase;
use App\Utils\DeviceDetectorCustomBot;
class DeviceDetector extends DeviceDetectorBase {
public function __construct($userAgent = '') {
if ($userAgent != '') {
$this->setUserAgent($userAgent);
}
# Library & Browser at top for small speed-up
$this->addClientParser('Library');
$this->addClientParser('Browser');
$this->addClientParser('MobileApp');
$this->addClientParser('FeedReader');
$this->addClientParser('MediaPlayer');
$this->addClientParser('PIM');
# not add DeviceParsers
$this->addBotParser(new Bot());
$this->addBotParser(new DeviceDetectorCustomBot());
}
public function parseBotRunner() {
return $this->parseBot();
}
public function parseClientRunner() {
return $this->parseClient();
}
}
<?php
namespace App\Utils;
use DeviceDetector\Parser\Bot;
class DeviceDetectorCustomBot extends Bot {
protected $fixtureFile = 'custombot.yml';
protected $parserName = 'custombot';
protected function getRegexesDirectory() {
return __DIR__;
}
}
<?php
namespace App\Utils;
use App\Utils\DeviceDetector;
use App\Utils\DeviceDetectorCache;
$dd = new DeviceDetector();
$is_bot = false;
$dd->setUserAgent('python-requests/2.21.0');
$dd->parseBotRunner();
if ($dd->isBot()) {
$is_bot = true;
} else {
$dd->parseClientRunner();
$client = $dd->getClient();
if ($client['type'] == 'library') {
$is_bot = true;
}
}
echo $is_bot;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment