PHP code example of evgeek / scraperapi-sdk

1. Go to this page and download the library: Download evgeek/scraperapi-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

evgeek / scraperapi-sdk example snippets




use Evgeek\Scraperapi\Client;

ent
$sdk = new Client('YOUR_TOKEN');

//Send request
$response = $sdk->get('https://example.com');

//Work with \Psr\Http\Message\ResponseInterface
echo $response->getBody()->getContents();

$defaultApiParams = [
    'country_code' => 'us', //activate country geotargetting
    'render' => true, //activate javascript rendering
    'premium' => false, //activate premium residential and mobile IPs
    'session_number' => 123, //reuse the same proxy
    'keep_headers' => true, //use your own custom headers
    'device_type' => 'mobile', //set mobile or desktop user agents
    'autoparse' => 'false', //activate auto parsing for select websites
];
$sdk = new Client('YOU_TOKEN', $defaultApiParams);

$defaultHeaders = [
    'Referer' => 'https://example.com/',
    'Accept' => 'application/json',
];
$sdk = new Client('YOU_TOKEN', ['keep_headers' => true], $defaultHeaders);

$response = $sdk->get(
    'https://example.com', 
    ['keep_headers' => true], 
    [
        'Referer' => 'https://example.com/',
        'Accept' => 'application/json',
    ]
);
$content = $response->getBody()->getContents();

$response = $sdk->post('https://example.com', $apiParams, $headers, $body, $formParams, $json);
$content = $response->getBody()->getContents();

$response = $sdk->postBody($url, $body, $apiParams, $headers);
$response = $sdk->postForm($url, $formParams, $apiParams, $headers);
$response = $sdk->postJson($url, $json, $apiParams, $headers);

$query = '
    query HeroNameAndFriends($episode: Episode) {
      hero(episode: $episode) {
        name
        friends {
          name
        }
      }
    }
';
$json = ['query' => $query, 'variables' => ['episode' => 'JEDI']];

$response = $sdk->postJson('https://example.com', $json);

//Create array with promises
$promises = [
    'first' => $sdk->getPromise('https://example.com', ['country_code' => 'us']),
    'second' => $sdk->postPromiseBody('https://example.com', 'payload'),
];
//Asynchronous fulfillment of promises
$responses = $sdk->resolvePromises($promises);

//Work with array of responses
foreach ($responses as $response) {
    echo $response->getBody()->getContents() . PHP_EOL;
}

$info = $sdk->accountInfo();
var_dump(json_decode($info, true));
POST
fopen()
array
array