bopoda/robots-txt-parser
Composer 安装命令:
composer require bopoda/robots-txt-parser
包简介
PHP Class for parsing robots.txt files according to Google, Yandex specifications.
关键字:
README 文档
README
RobotsTxtParser — PHP class for parsing all the directives of the robots.txt files
RobotsTxtValidator — PHP class for check is url allow or disallow according to robots.txt rules.
Try demo of RobotsTxtParser on-line on live domains.
Parsing is carried out according to the rules in accordance with Google & Yandex specifications:
Last improvements:
- Pars the Clean-param directive according to the clean-param syntax.
- Deleting comments (everything following the '#' character, up to the first line break, is disregarded)
- The improvement of the Parse of Host — the intersection directive, should refer to the user-agent '*'; If there are multiple hosts, the search engines take the value of the first.
- From the class, unused methods are removed, refactoring done, the scope of properties of the class is corrected.
- Added more test cases, as well as test cases added to the whole new functionality.
- RobotsTxtValidator class added to check if url is allowed to parsing.
- With version 2.0, the speed of RobotsTxtParser was significantly improved.
Supported Directives:
- DIRECTIVE_ALLOW = 'allow';
- DIRECTIVE_DISALLOW = 'disallow';
- DIRECTIVE_HOST = 'host';
- DIRECTIVE_SITEMAP = 'sitemap';
- DIRECTIVE_USERAGENT = 'user-agent';
- DIRECTIVE_CRAWL_DELAY = 'crawl-delay';
- DIRECTIVE_CLEAN_PARAM = 'clean-param';
- DIRECTIVE_NOINDEX = 'noindex';
Installation
Install the latest version with
composer require bopoda/robots-txt-parser
Run tests
Run phpunit tests using command
php vendor/bin/phpunit
Usage example
You can start the parser by getting the content of a robots.txt file from a website:
$parser = new RobotsTxtParser(file_get_contents('http://example.com/robots.txt')); var_dump($parser->getRules());
Or simply using the contents of the file as input (ie: when the content is already cached):
$parser = new RobotsTxtParser(" User-Agent: * Disallow: /ajax Disallow: /search Clean-param: param1 /path/file.php User-agent: Yahoo Disallow: / Host: example.com Host: example2.com "); var_dump($parser->getRules());
This will output:
array(2) { ["*"]=> array(3) { ["disallow"]=> array(2) { [0]=> string(5) "/ajax" [1]=> string(7) "/search" } ["clean-param"]=> array(1) { [0]=> string(21) "param1 /path/file.php" } ["host"]=> string(11) "example.com" } ["yahoo"]=> array(1) { ["disallow"]=> array(1) { [0]=> string(1) "/" } } }
In order to validate URL, use the RobotsTxtValidator class:
$parser = new RobotsTxtParser(file_get_contents('http://example.com/robots.txt')); $validator = new RobotsTxtValidator($parser->getRules()); $url = '/'; $userAgent = 'MyAwesomeBot'; if ($validator->isUrlAllow($url, $userAgent)) { // Crawl the site URL and do nice stuff }
Contribution
Feel free to create PR in this repository. Please, follow PSR style.
See the list of contributors which participated in this project.
Final Notes:
Please use v2.0+ version which works by same rules but is more highly performance.
bopoda/robots-txt-parser 适用场景与选型建议
bopoda/robots-txt-parser 是一款 基于 DIGITAL Command Language 开发的 Composer 扩展包,目前已累计 288.12k 次下载、GitHub Stars 达 47, 最近一次更新时间为 2019 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parser」 「google」 「robots.txt」 「yandex」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bopoda/robots-txt-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bopoda/robots-txt-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bopoda/robots-txt-parser 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
An MT940 bank statement parser for PHP
Robots.txt Generator
A route for serving a basic robots.txt in Laravel 5.1+, based on configuration settings.
Laravel integration for the jsonapi.org parser
Agnostic model to efficiently query and scroll any kind of data (SQL, Search engine, HTTP API, CSV, ...) and push them anywhere with a ETL
统计信息
- 总下载量: 288.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 48
- 点击次数: 25
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-02