antheta / falcon
PHP 网站抓取和解析器。抓取单个或多个网站以获取电子邮件地址或 IP 地址/代理。
0.0.1
2023-10-09 10:16 UTC
Requires
- duzun/hquery: ^3.0
Requires (Dev)
- pestphp/pest: ^1.20
This package is not auto-updated.
Last update: 2024-09-26 12:26:30 UTC
README
Falcon 是一个开源(MIT 许可)的高性能 PHP 网站抓取器,具有内置解析器和可扩展性。
请注意,此库不应用于收集电子邮件或其他个人信息以进行垃圾邮件。
文档
特性
- 许多不同的内置解析器。
- 近乎无限的扩展性
- 自定义解析器支持。
- 自定义正则表达式支持。
- 自定义驱动程序(抓取器)支持。
安装
Composer
composer require antheta/falcon
使用方法
运行抓取器
$falcon = Falcon::getInstance()->run("https://example.com/"); $result = $falcon->parse()->results(); // use all available parsers and get all results
上面的例子抓取了 URL 并返回一个数组。
使用特定解析器
如果您希望从结果中获取特定资源
$falcon = Falcon::getInstance()->run("https://example.com/"); // only returns emails $emails = $falcon->parse(["email", "ip"])->emails();
方法
辅助方法用于返回结果
自定义正则表达式
要向解析器添加您自己的正则表达式,只需使用 addRegexes
辅助方法即可
// this will attempt to parse emails with the given regex $falcon = Falcon::getInstance() ->addRegexes("email", ["/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-ddd]+/i"]) ->run("https://example.com/")->parse()->emails(); // you can extend this to other parsers as well and add as many regexes as needed $falcon = Falcon::getInstance() // regexes for emails ->addRegexes("email", [ "/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-ddd]+/i", "/[\._a-zA-Z0-9-]+\(at\)[\._a-zA-Z0-9-]+/i", ]) // regexes for phonenumbers ->addRegexes("phonenumber", [ "/([\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,12})/", ]) ->run("https://example.com/") ->parse() ->results();
自定义解析器
使用自定义解析器,您可以控制解析器返回的数据类型
$falcon = Falcon::getInstance(); $falcon->addParser("myCustomParser", fn ($payload) => MyParser($payload)); function MyParser($payload) { // your custom logic here } // or $falcon->addParser("myCustomParser", function($payload) { // your custom logic here }); // result from your parser $falcon->parse("myCustomParser")->results()["myCustomParser"];
自定义驱动程序
驱动程序用于抓取网站并将 HTML 返回给 Falcon。驱动程序还可以用于编写完全自定义的逻辑并将其保存到 Falcon 以供以后使用。首先创建一个扩展 DriverInterface
接口的驱动程序类,并在类中实现特定的驱动程序逻辑。
$falcon = Falcon::getInstance(); $falcon->addDrivers([ "myDriver" => MyDriver::class ]);
抓取动态内容
您可以从 hQuery 迁移到无头 JavaScript 浏览器,如 CapserJS & Phantom,以加载动态内容。这样,您还可以抓取在初始页面加载后动态加载的数据。
查看 Falcon 驱动程序 以获取入门信息。
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。