rebelinblue / fluent-web-crawler
具有流畅界面的网络爬虫
1.0.5
2020-05-07 13:47 UTC
Requires
- php: >=7.1.0
- fabpot/goutte: ^3.2
Requires (Dev)
- codeclimate/php-test-reporter: ^0.4.4
- friendsofphp/php-cs-fixer: ^2.16
- larapack/dd: ^1.1
- php-parallel-lint/php-console-highlighter: ^0.4
- php-parallel-lint/php-parallel-lint: ^1.2
- phpmd/phpmd: ^2.8
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^3.5
README
Fluent Web Crawler
一个具有良好流畅界面的PHP网络爬取库。
是 laravel/browser-kit-testing 的分支,重新用于与真实的HTTP请求一起使用。
是为我在Sainsbury's工作的一个项目开发的。
需求
PHP 7.1+ 和 Goutte 3.1+
安装
推荐通过 Composer 安装库。
在您的 composer.json
文件中将 rebelinblue/fluent-web-crawler
添加为必需依赖项
composer require rebelinblue/fluent-web-crawler
用法
创建爬虫实例
use REBELinBLUE\Crawler; $crawler = new Crawler();
访问URL
$crawler->visit('http://www.example.com');
与页面交互
$crawler->type('username', 'admin') ->type('password', 'password') ->press('Login'); // This can also be written as the following $crawler->submitForm('Login', [ 'username' => 'admin', 'password' => 'password', ]);
检查响应是否符合预期
if ($crawler->dontSeeText('Hello World')) { throw new \Exception('The page does not contain the expected text'); }
有关可用操作的完整列表,请参阅 api.md。
自定义HTTP客户端设置
如果您想自定义使用的Goutte实例(或更可能的是Guzzle实例),您可以在构建类时注入自己的实例。例如,您可能想增加Guzzle的超时时间
use Goutte\Client as GoutteClient; use GuzzleHttp\Client as GuzzleClient; $goutteClient = new GoutteClient(); $guzzleClient = new GuzzleClient([ 'timeout' => 60, ]); $goutteClient->setClient($guzzleClient); $crawler = new Crawler($goutteClient);
进一步阅读
Fluent Crawler 是以下PHP库的包装器。
- Goutte 网络爬取器。
- Symfony BrowserKit,CssSelector 和 DomCrawler。
- Guzzle HTTP客户端。