searchdata/php-sdk

SearchData 是一个API,允许使用旋转代理来防止封禁,刮取各种搜索引擎,如Google、Bing、Yandex等。此PHP SDK使您更容易在任意项目中实现API的使用。

1.0.2 2021-09-15 08:55 UTC

This package is auto-updated.

Last update: 2024-09-15 16:02:25 UTC


README

SearchData 是一个API,允许使用旋转代理来防止封禁,刮取各种搜索引擎,如Google、Bing、Yandex等。此PHP SDK使您更容易在任意项目中实现API的使用。

依赖

本包的唯一依赖项与这里的php-curl库相关。

要安装它,只需运行以下命令

sudo apt-get install php-curl

安装

在项目主目录中运行以下命令

composer require searchdata/php-sdk

API密钥

要使用API和SDK,您需要一个API密钥。您可以通过在SearchData注册来获取一个。

此SDK为searchdata.io的每个搜索引擎提供了一个类。以下是列表

使用方法

使用SDK相当简单。以下是API GET调用的示例

<?php 

require_once __DIR__ . '/vendor/autoload.php';

use SearchdataSDK\SearchdataGoogleSearch;
use SearchdataSDK\SearchdataLocations;

$googleSearch = new SearchdataGoogleSearch('YOUR_API_KEY');
$locationsAPI = new SearchdataLocations();

try {
    $locations = $locationsAPI->execute('New York', 1)['body'];

    $googleSearch->set_q('test');
    $googleSearch->set_device('mobile');
    $googleSearch->set_lr('lang_en|lang_ar');
    $googleSearch->set_location($locations[0]['location']);

    $response = $googleSearch->execute();
    echo json_encode($response['body']);
} catch (Exception $e) {
    echo $e->getMessage();
}

或者,您可以使用executeRaw函数,它允许您以关联数组的形式发送参数

<?php 

require_once __DIR__ . '/vendor/autoload.php';

use SearchdataSDK\SearchdataGoogleSearch;
use SearchdataSDK\SearchdataLocations;

$googleSearch = new SearchdataGoogleSearch('YOUR_API_KEY');
$locationsAPI = new SearchdataLocations();

try {
    $locations = $locationsAPI->execute('New York', 1)['body'];

    $response = $googleSearch->executeRaw([
        'q' => 'test',
        'device' => 'mobile',
        'lr' => 'lang_en|lang_ar',
        'location' => $locations[0]['location']
    ]);
    echo json_encode($response['body']);
} catch (Exception $e) {
    echo $e->getMessage();
}

有关参数的更多信息,请参阅我们的文档