glow / robots
该包已被废弃,不再维护。没有建议的替代包。
robots.txt 解析器和生成工具集
1.5
2015-12-08 18:38 UTC
Requires
- php: >=5.5.0
- tomverran/robots-txt-checker: 1.02
Requires (Dev)
- codacy/coverage: dev-master
- fzaninotto/faker: ^1.5
- phpunit/phpunit: ^4.8
This package is not auto-updated.
Last update: 2018-06-27 18:59:32 UTC
README
一个用于解析、验证和生成 robots.txt 文件的 PHP 5.5(或更高版本)工具集。
安装
推荐使用 Composer 安装 Glow\Robots。
composer require glow/robots
徽章
服务 | 徽章 |
---|---|
SensioLabs | |
Codecov | |
Travis CI | |
Gitter Chat | |
Packagist | |
Codacy |
用法
解析器
解析器类用于将 robots.txt 内容解析为可读数组。它可以优雅地跳过发生的错误,并在某些情况下在解析过程中修复错误。
方法
方法 | 可见性 | 描述 |
---|---|---|
__construct | public | 类构造 |
parse | protected | 解析 robots.txt 源内容 |
parseLine | protected | 解析 robots.txt 行的工作方法 |
getParsed | public | 返回解析内容 |
getErrors | public | 返回所有发生的错误 |
setError | protected | 设置错误 |
incrementCounter | protected | 增加解析过程中使用的计数器 |
isAllowed | public | 用于确定 URL 路径是否允许被爬取 |
isDisallowed | public | 用于确定 URL 路径不允许被爬取 |
getTR | public | 返回 tomverran/robots-txt-checker 类 |
getElements | public | 返回解析过程中搜索的元素 |
setElements | public | 设置解析过程中搜索的元素 |
getMeta | public | 返回解析过程中提取的元数据 |
getSitemaps | public | 返回解析过程中发现的 sitemap 数组 |
getUserAgentData | public | 返回指定用户代理的所有解析指令 |
getUserAgentAllow | public | 返回指定用户代理的所有允许元素 |
getUserAgentDisallow | public | 返回指定用户代理的所有不允许元素 |
基本用法
解析器使用的基本示例
$p = new Glow\Robots\Parser(file_get_contents('http://cnn.com/robots.txt'));
验证
验证类用于扫描错误并验证 robots.txt 内容。
方法
方法 | 可见性 | 描述 |
---|---|---|
__construct | public | 类构造 |
check | public | 检查源错误 |
基本用法
验证使用的基本示例
$p = new Glow\Robots\Validate(file_get_contents('http://cnn.com/robots.txt'));
if ($p->check()===false) {
//something is wrong with our robots.txt file
}
else {
//hooray everything is good with our file!
}