爬虫版本检测代码优化

This commit is contained in:
Zhai Yiming 2017-07-14 10:58:24 +08:00
parent ad0b5301a4
commit 8cdd62dcfe

View File

@ -102,14 +102,13 @@ class Access_UA
{
if ($this->robotID === null) {
if (!empty($this->ua)) {
if (preg_match('#([a-zA-Z0-9]+\s*(?:bot|spider))[ /]*([0-9.]*)#i', $this->ua, $matches)) {
if (preg_match('#([a-zA-Z0-9]+\s*(?:bot|spider))[ /v]*([0-9.]*)#i', $this->ua, $matches)) {
$this->robotID = $this->robotName = $matches[1];
$this->robotVersion = $matches[2];
}
foreach (self::$robots as $val) {
if (strpos($this->ual, $this->filter($val)) !== false) {
$this->robotID = $this->robotName = $val;
$this->robotVersion = '';
}
}
}