scrapemax/scrapemax-php

此包的最新版本(0.0.6)没有可用的许可证信息。

Scrapemax PHP API 客户端

0.0.6 2023-12-09 20:23 UTC

This package is not auto-updated.

Last update: 2024-09-29 00:27:03 UTC


README

Scrapemax API 的 PHP 客户端。

安装

composer require scrapemax/scrapemax-php

用法

require_once 'vendor/autoload.php';

use Scrapemax\ScrapemaxClient;

// Instantiate the ScrapeClient with the API base URL and key
$client = new ScrapemaxClient('https://api.scrapemax.com', 'your_api_key');

// Use the ScrapeClient to make API requests
$response = $client->scrape([
    'js_enabled' => 1,
    'target_url' => 'https://example.com/page',
    'proxy' => 'premium',
    'type' => 'data'
]);

print_r($response);

自定义 Guzzle 客户端

如果您对 Guzzle 客户端有特定的要求,您可以通过将自定义实例作为第三个参数传递给 ScrapeClient 构造函数来使用自己的实例。确保自定义客户端包含 'base_uri' 选项以指定 API 端点。以下是一个示例

use GuzzleHttp\Client as GuzzleClient;
use Scrapemax\ScrapemaxClient;

// Instantiate a custom Guzzle client with additional configuration
$customGuzzleClient = new GuzzleClient([
    'base_uri' => 'https://api.scrapemax.com',
    'timeout' => 5,
    // Add any other Guzzle client options as needed
]);

// Instantiate the ScrapeClient with the API base URL, key, and custom Guzzle client
$client = new ScrapemaxClient('https://api.scrapemax.com', 'your_api_key', $customGuzzleClient);

// Use the ScrapeClient to make API requests with the custom Guzzle client
$response = $client->scrape([
    'js_enabled' => 1,
    'target_url' => 'https://example.com/page',
    'proxy' => 'premium',
    'type' => 'data'
]);

print_r($response);