大蚁链 / fink
检查链接
0.11.2
2024-03-16 12:08 UTC
Requires
- php: ^8.0
- amphp/dns: ^v1.2.2
- amphp/file: ^1
- amphp/http-client: ^4.1.0
- amphp/http-client-cookies: ^1
- league/uri: ^6
- phpactor/console-extension: ~0.1
- phpactor/container: ^1.0
- webmozart/path-util: ^2.3
Requires (Dev)
- amphp/phpunit-util: ^1.3
- friendsofphp/php-cs-fixer: ^3.0
- phpactor/test-utils: ^1.0
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-16 13:13:21 UTC
README
Fink(发音为“Phpink”)是一个命令行工具,用PHP编写,用于检查HTTP链接。
- 检查网站中的断链或错误页面。
- 异步HTTP请求。
安装
作为独立工具或项目依赖项安装
作为项目依赖项安装
$ composer require dantleech/fink --dev
从PHAR安装
从发行版页面下载PHAR。
使用Box构建自己的PHAR
通过克隆此存储库并运行来构建自己的PHAR:
$ ./vendor/bin/box compile
用法
使用单个URL运行命令以开始爬取
$ ./vendor/bin/fink https://www.example.com
使用 --output=somefile
将每个URL的详细日志信息记录为JSON格式,包括
url
:测试的URL。status
:HTTP状态码。referrer
:链接到URL的页面。referrer_title
:引用元素的值(例如,链接标题)。referrer_xpath
:引用文档中节点的路径。distance
:与起始文档的距离(以链接数量计)。request_time
:发送请求所需的时间(以微秒计)。timestamp
:请求的时间。exception
:遇到的任何运行时异常(例如,格式错误的URL等)。
参数
url
(多个):指定一个或多个要爬取的基本URL(必填)。
选项
--client-max-body-size
:HTTP客户端的最大正文大小(以字节为单位)。--client-max-header-size
:HTTP客户端的最大标题大小(以字节为单位)。--client-redirects=5
:设置客户端应重定向的最大次数(0
表示从不重定向)。--client-security-level=1
:设置默认SSL 安全级别--client-timeout=15000
:设置客户端等待响应的最大时间(以毫秒计),默认为15,000(15秒)。--concurrency
:要使用的并发HTTP请求的数量。--display-bufsize=10
:设置显示时考虑的URL数量。--display=+memory
:设置、添加或删除运行时显示的元素(使用前缀-
或+
修改默认设置)。--exclude-url=logout
:(多个)排除与给定PCRE模式匹配的URL。--header="Foo: Bar"
:(多个)指定自定义标题。--help
:显示可用选项。--include-link=foobar.html
:包括给定的链接,就像它从基本URL链接一样。--insecure
:不要验证SSL证书。--load-cookies
:从cookies.txt加载。--max-distance
:从基本URL允许的最大距离(如果没有指定,则没有限制)。--max-external-distance
:限制从基本URL的外部(不连续)距离。--no-dedupe
:不过滤重复URL(可能导致非终止进程)。--output=out.json
:将每个URL的JSON报告输出到指定的文件(截断现有内容)。--publisher=csv
:设置发布者(默认为json
),可以是json
或csv
。--rate
:设置每秒请求的最大次数。--stdout
:直接输出到STDOUT,禁用显示和任何指定的输出文件。
示例
爬取单个网站
$ fink http://www.example.com --max-external-distance=0
爬取单个网站并检查外部链接的状态
$ fink http://www.example.com --max-external-distance=1
使用 jq
分析结果
jq 是一个可以用于查询和操作JSON数据的工具。
$ fink http://www.example.com -x0 -oreport.json
$ cat report.json| jq -c '. | select(.status==404) | {url: .url, referrer: .referrer}' | jq
爬取登录后的页面
# create a cookies file for later re-use (simulate a login in this case via HTTP-POST)
$ curl -L --cookie-jar mycookies.txt -d username=myLogin -d password=MyP4ssw0rd https://www.example.org/my/login/url
# re-use the cookies file with your fink crawl command
$ fink https://www.example.org/myaccount --load-cookies=mycookies.txt
注意:在计算机A上创建cookie jar,存储它,然后在例如Linux服务器上再次读取是不可能的。您需要从相同的IP地址创建cookie文件,因为否则服务器端会话处理可能会因为IP不匹配而无法继续http会话。
退出代码
0
:所有URL都成功。1
:意外的运行时错误。2
:至少有一个URL未能成功解析。