diggin / diggin-robotrules
Robots Exclusion Protocol (robots.txt 等) 的解析器/处理器
0.10.0
2016-02-26 14:56 UTC
Requires
- php: >=5.3.4
Requires (Dev)
- phpunit/phpunit: ~4.8
- satooshi/php-coveralls: ~0.6
- zendframework/zend-uri: ~2.3
This package is auto-updated.
Last update: 2024-09-06 15:36:49 UTC
README
PHP解析器/处理器用于Robots Exclusion Protocol (robots.txt 等..)
特性
-
实现 http://www.robotstxt.org/norobots-rfc.txt
- [已完成] “3.2.2 允许和拒绝行” - 作为测试用例
- [已完成] “4.示例” 作为测试用例
-
通过Nutch的测试代码 参考
- [已完成] @see tests/Diggin/RobotRules/Imported/NutchTest.php
-
解析和处理html-meta
待办事项
- 处理Crawl-Delay
- 使用Google Test robots.txt工具同步或测试一小部分模式
- 使用PHPPEG重写。(因为当前基于preg*的解析器难以实现。)
- 更多测试,不断重构...
用法
<?php use Diggin\RobotRules\Accepter\TxtAccepter; use Diggin\RobotRules\Parser\TxtStringParser; $robotstxt = <<<'ROBOTS' # sample robots.txt User-agent: YourCrawlerName Disallow: User-agent: * Disallow: /aaa/ #comment ROBOTS; $accepter = new TxtAccepter; $accepter->setRules(TxtStringParser::parse($robotstxt)); $accepter->setUserAgent('foo'); var_dump($accepter->isAllow('/aaa/')); //false var_dump($accepter->isAllow('/b.html')); //true $accepter->setUserAgent('YourCrawlerName'); var_dump($accepter->isAllow('/aaa/')); // true
安装
Diggin_RobotRules遵循PSR-0,因此要将命名空间Diggin\RobotRules注册到您的ClassLoader中。
通过composer安装
- $php composer.phar require diggin/diggin-robotrules "dev-master"
许可证
Diggin_RobotRules采用新BSD许可证。
其他语言的参考和替代方案。
- Perl
- Python
- Ruby