68publishers/crawler-client-php
Composer 安装命令:
composer require 68publishers/crawler-client-php
包简介
README 文档
README
Crawler Client PHP
PHP Client for 68publishers/crawler
Installation
$ composer require 68publishers/crawler-client-php
Client initialization
The client instance is simply created by calling the static method create().
use SixtyEightPublishers\CrawlerClient\CrawlerClient; $client = CrawlerClient::create('<full url to your crawler instance>');
The Guzzle library is used to communicate with the Crawler API. If you want to pass some custom options to the configuration for Guzzle, use the second optional parameter.
use SixtyEightPublishers\CrawlerClient\CrawlerClient; $client = CrawlerClient::create('<full url to your crawler instance>', [ 'timeout' => 0, ]);
Requests to the Crawler API must always be authenticated, so we must provide credentials.
use SixtyEightPublishers\CrawlerClient\CrawlerClient; use SixtyEightPublishers\CrawlerClient\Authentication\Credentials; $client = CrawlerClient::create('<full url to your crawler instance>'); $client = $client->withAuthentication(new Credentials('<username>', '<password>'));
It should be pointed out that the client is immutable - calling the with* methods always returns a new instance.
This is all that is needed for the client to work properly. You can read about other options on the Advanced options page.
Nette Framework integration
For integration with the Nette Framework please follow this link.
Working with scenarios
Scenarios are handled by ScenarioController.
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ScenariosController; $controller = $client->getController(ScenariosController::class);
List scenarios
/** * @param int $page * @param int $limit * @param array<string, string|array<string>> $filter * * @returns \SixtyEightPublishers\CrawlerClient\Controller\Scenario\ScenarioListingResponse * * @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException */
$response = $controller->listScenarios(1, 10); $filteredResponse = $controller->listScenarios(1, 10, [ 'name' => 'Test', 'status' => 'failed', ])
Get scenario
/** * @param string $scenarioId * * @returns \SixtyEightPublishers\CrawlerClient\Controller\Scenario\ScenarioResponse * * @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException * @throws \SixtyEightPublishers\CrawlerClient\Exception\NotFoundException */
$response = $controller->getScenario('<id>');
Run scenario
/** * @param \SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody $requestBody * * @returns \SixtyEightPublishers\CrawlerClient\Controller\Scenario\ScenarioResponse * * @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException */
As a scenario config we can pass a normal array or use prepared value objects. Both options are valid.
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody; $requestBody = new ScenarioRequestBody( name: 'My scenario', flags: ['my_flag' => 'my_flag_value'], config: [ 'scenes' => [ /* ... */ ], 'options' => [ /* ... */ ], 'entrypoint' => [ /* ... */ ], ], ) $response = $controller->runScenario($requestBody);
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\ScenarioConfig; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Entrypoint; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Action; $requestBody = new ScenarioRequestBody( name: 'My scenario', flags: ['my_flag' => 'my_flag_value'], config: (new ScenarioConfig(new Entrypoint('<url>', 'default'))) ->withOptions(/* ... */) ->withScene('default', [ new Action('...', [ /* ... */ ]) new Action('...', [ /* ... */ ]) ]), ) $response = $controller->runScenario($requestBody);
Validate scenario
/** * @param \SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody $requestBody * * @returns \SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValidateScenarioResponse */
As a scenario config we can pass a normal array or use prepared value objects. Both options are valid.
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody; $requestBody = new ScenarioRequestBody( name: 'My scenario', flags: ['my_flag' => 'my_flag_value'], config: [ 'scenes' => [ /* ... */ ], 'options' => [ /* ... */ ], 'entrypoint' => [ /* ... */ ], ], ) $response = $controller->validateScenario($requestBody);
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\RequestBody\ScenarioRequestBody; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\ScenarioConfig; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Entrypoint; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Action; $requestBody = new ScenarioRequestBody( name: 'My scenario', flags: ['my_flag' => 'my_flag_value'], config: (new ScenarioConfig(new Entrypoint('<url>', 'default'))) ->withOptions(/* ... */) ->withScene('default', [ new Action('...', [ /* ... */ ]) new Action('...', [ /* ... */ ]) ]), ) $response = $controller->validateScenario($requestBody);
Abort scenario
/** * @param string $scenarioId * * @returns \SixtyEightPublishers\CrawlerClient\Controller\Common\NoContentResponse * * @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException * @throws \SixtyEightPublishers\CrawlerClient\Exception\NotFoundException */
$response = $controller->abortScenario('<id>');
Working with scenario schedulers
Scenario schedulers are handled by ScenarioSchedulersController.
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulersController; $controller = $client->getController(ScenarioSchedulersController::class);
List scenario schedulers
/** * @param int $page * @param int $limit * @param array<string, string|array<string>> $filter * * @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulerListingResponse * * @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException */
$response = $controller->listScenarioSchedulers(1, 10); $filteredResponse = $controller->listScenarioSchedulers(1, 10, [ 'name' => 'Test', 'userId' => '<id>', ])
Get scenario scheduler
/** * @param string $scenarioSchedulerId * * @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulerResponse * * @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException * @throws \SixtyEightPublishers\CrawlerClient\Exception\NotFoundException */
$response = $controller->getScenarioScheduler('<id>'); $etag = $response->getEtag(); # you need Etag for update
Create scenario scheduler
/** * @param \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody $requestBody * * @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulerResponse * * @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException */
As a scenario config we can pass a normal array or use prepared value objects. Both options are valid.
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody; $requestBody = new ScenarioSchedulerRequestBody( name: 'My scenario', flags: ['my_flag' => 'my_flag_value'], active: true, expression: '0 2 * * *', config: [ 'scenes' => [ /* ... */ ], 'options' => [ /* ... */ ], 'entrypoint' => [ /* ... */ ], ], ) $response = $controller->createScenarioScheduler($requestBody); $etag = $response->getEtag(); # you need Etag for update
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\ScenarioConfig; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Entrypoint; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Action; $requestBody = new ScenarioSchedulerRequestBody( name: 'My scenario', flags: ['my_flag' => 'my_flag_value'], active: true, expression: '0 2 * * *', config: (new ScenarioConfig(new Entrypoint('<url>', 'default'))) ->withOptions(/* ... */) ->withScene('default', [ new Action('...', [ /* ... */ ]) new Action('...', [ /* ... */ ]) ]), ) $response = $controller->runScenario($requestBody); $etag = $response->getEtag(); # you need Etag for update
Update scenario scheduler
/** * @param string $scenarioSchedulerId * @param string $etag * @param \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody $requestBody * * @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulerResponse * * @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException * @throws \SixtyEightPublishers\CrawlerClient\Exception\PreconditionFailedException */
As a scenario config we can pass a normal array or use prepared value objects. Both options are valid.
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody; $requestBody = new ScenarioSchedulerRequestBody( name: 'My scenario', flags: ['my_flag' => 'my_flag_value'], active: true, expression: '0 2 * * *', config: [ 'scenes' => [ /* ... */ ], 'options' => [ /* ... */ ], 'entrypoint' => [ /* ... */ ], ], ) $response = $controller->updateScenarioScheduler('<id>', '<etag>', $requestBody); $etag = $response->getEtag(); # you need Etag for next update
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\ScenarioConfig; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Entrypoint; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Action; $requestBody = new ScenarioSchedulerRequestBody( name: 'My scenario', flags: ['my_flag' => 'my_flag_value'], active: true, expression: '0 2 * * *', config: (new ScenarioConfig(new Entrypoint('<url>', 'default'))) ->withOptions(/* ... */) ->withScene('default', [ new Action('...', [ /* ... */ ]) new Action('...', [ /* ... */ ]) ]), ) $response = $controller->updateScenarioScheduler('<id>', '<etag>', $requestBody); $etag = $response->getEtag(); # you need Etag for next update
Validate scenario scheduler
/** * @param \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody $requestBody * * @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ValidateScenarioSchedulerResponse */
As a scenario config we can pass a normal array or use prepared value objects. Both options are valid.
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody; $requestBody = new ScenarioSchedulerRequestBody( name: 'My scenario', flags: ['my_flag' => 'my_flag_value'], active: true, expression: '0 2 * * *', config: [ 'scenes' => [ /* ... */ ], 'options' => [ /* ... */ ], 'entrypoint' => [ /* ... */ ], ], ) $response = $controller->validateScenarioScheduler($requestBody);
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\ScenarioConfig; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Entrypoint; use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Action; $requestBody = new ScenarioSchedulerRequestBody( name: 'My scenario', flags: ['my_flag' => 'my_flag_value'], active: true, expression: '0 2 * * *', config: (new ScenarioConfig(new Entrypoint('<url>', 'default'))) ->withOptions(/* ... */) ->withScene('default', [ new Action('...', [ /* ... */ ]) new Action('...', [ /* ... */ ]) ]), ) $response = $controller->validateScenarioScheduler($requestBody);
Activate/deactivate scenario scheduler
/** * @param string $scenarioSchedulerId * * @returns \SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\ScenarioSchedulerResponse * * @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException * @throws \SixtyEightPublishers\CrawlerClient\Exception\NotFoundException */
use SixtyEightPublishers\CrawlerClient\Controller\ScenarioScheduler\RequestBody\ScenarioSchedulerRequestBody; # to activate the scenario scheduler: $response = $controller->activateScenarioScheduler('<id>'); # to deactivate the scenario scheduler: $response = $controller->deactivateScenarioScheduler('<id>');
Delete scenario scheduler
/** * @param string $scenarioSchedulerId * * @returns \SixtyEightPublishers\CrawlerClient\Controller\Common\NoContentResponse * * @throws \SixtyEightPublishers\CrawlerClient\Exception\BadRequestException * @throws \SixtyEightPublishers\CrawlerClient\Exception\NotFoundException */
$response = $controller->deleteScenarioScheduler('<id>');
License
The package is distributed under the MIT License. See LICENSE for more information.
68publishers/crawler-client-php 适用场景与选型建议
68publishers/crawler-client-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 713 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「scraper」 「crawler」 「crawling」 「scraping」 「68publishers」 「crawler-client」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 68publishers/crawler-client-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 68publishers/crawler-client-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 68publishers/crawler-client-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A lightweight, dependency free PHP class that acts as wrapper for Crawlbase API
A SilverStripe module to optimise the Meta, crawling, indexing, and sharing of your website content (forked from Cyber-Duck/Silverstripe-SEO)
Crawlzone is a fast asynchronous internet crawling framework aiming to provide open source web search and testing solution. It can be used for a wide range of purposes, from extracting and indexing structured data to monitoring and automated testing.
TYPO3 extension for generating .well-known/llm.txt links according to llmstxt.org specification
A tool for scraping URL resources (oEmbed, OpenGraph, Twitter cards, JSON-LD)
统计信息
- 总下载量: 713
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2023-06-09