PHP code example of proxycrawl / proxycrawl

1. Go to this page and download the library: Download proxycrawl/proxycrawl 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/ */

    

proxycrawl / proxycrawl example snippets


$api = new ProxyCrawl\CrawlingAPI(['token' => 'YOUR_PROXYCRAWL_TOKEN']);

$api->get(string $url, array $options = []);

$response = $api->get('https://www.facebook.com/britneyspears');
if ($response->statusCode === 200) {
  echo $response->body;
}

$response = $api->get('https://www.reddit.com/r/pics/comments/5bx4bx/thanks_obama/', [
  'user_agent' => 'Mozilla/5.0 (Windows NT 6.2; rv:20.0) Gecko/20121202 Firefox/30.0',
  'format' => 'json'
]);
if ($response->statusCode === 200) {
  echo $response->body;
}

$response = $api->get('https://www.reddit.com/r/pics/comments/5bx4bx/thanks_obama/', [
  'store' => true
]);

if ($response->statusCode === 200) {
  echo 'storage url: ' . $response->headers->storage_url . PHP_EOL;
}

$api->post(string $url, array or string $data, array options = []);

$response = $api->post('https://producthunt.com/search', ['text' => 'example search']);
if ($response->statusCode === 200) {
  echo $response->body;
}

$response = $api->post('https://httpbin.org/post', json_encode(['some_json' => 'with some value']), ['post_content_type' => 'json']);
if ($response->statusCode === 200) {
  echo $response->body;
}

$api->put(string $url, array or string $data, array options = []);

$response = $api->put('https://producthunt.com/search', ['text' => 'example search']);
if ($response->statusCode === 200) {
  echo $response->body;
}

$api = new ProxyCrawl\CrawlingAPI(['token' => 'YOUR_JAVASCRIPT_TOKEN']);

$response = $api->get('https://www.nfl.com');
if ($response->statusCode === 200) {
  echo $response->body;
}

$response = $api->get('https://www.freelancer.com', ['page_wait' => 5000]);
if ($response->statusCode === 200) {
  echo $response->body;
}

$response = $api->get('https://craiglist.com');
echo $response->headers->original_status . PHP_EOL;
echo $response->headers->pc_status . PHP_EOL;

$api = new ProxyCrawl\ScraperAPI(['token' => 'YOUR_PROXYCRAWL_TOKEN']);

$response = $api->get('https://www.amazon.com/DualSense-Wireless-Controller-PlayStation-5/dp/B08FC6C75Y/');
echo 'status code: ' . $response->statusCode . PHP_EOL;
if ($response->statusCode === 200) {
  var_dump($response->json); // Will print scraped Amazon details
}

$api = new ProxyCrawl\LeadsAPI(['token' => 'YOUR_PROXYCRAWL_TOKEN']);

$response = $api->getFromDomain('target.com');
if ($response->statusCode === 200) {
  foreach ($response->json->leads as $key => $lead) {
    echo $lead->email . PHP_EOL;
  }
}

$api = new ProxyCrawl\ScreenshotsAPI(['token' => 'YOUR_PROXYCRAWL_TOKEN']);
$response = $api->get('https://www.apple.com');
echo 'success: ' . $response->headers->success . PHP_EOL;
echo 'remaining requests: ' . $response->headers->remaining_requests . PHP_EOL;
file_put_contents('apple.jpg', $response->body);

$api = new ProxyCrawl\ScreenshotsAPI(['token' => 'YOUR_PROXYCRAWL_TOKEN']);
$response = $api->get('https://www.apple.com', [
  'callback' => function($filepath) {
    echo 'filepath: ' . $filepath . PHP_EOL;
  }
]);
echo 'success: ' . $response->headers->success . PHP_EOL;
echo 'remaining requests: ' . $response->headers->remaining_requests . PHP_EOL;

$api = new ProxyCrawl\ScreenshotsAPI(['token' => 'YOUR_PROXYCRAWL_TOKEN']);
$response = $api->get('https://www.apple.com', [
  'saveToPath' => 'apple.jpg',
  'callback' => function($filepath) {
    echo 'filepath: ' . $filepath . PHP_EOL;
  }
]);
echo 'success: ' . $response->headers->success . PHP_EOL;
echo 'remaining requests: ' . $response->headers->remaining_requests . PHP_EOL;

$api = new ProxyCrawl\StorageAPI(['token' => 'YOUR_PROXYCRAWL_TOKEN']);

$response = $api->get('https://www.apple.com');

echo 'status code: ' . $response->statusCode . PHP_EOL;
if ($response->statusCode === 200) {
  echo 'body: ' . $response->body . PHP_EOL;
  echo 'original status: ' . $response->headers->original_status . PHP_EOL;
  echo 'proxycrawl status: ' . $response->headers->pc_status . PHP_EOL;
  echo 'rid: ' . $response->headers->rid . PHP_EOL;
  echo 'url: ' . $response->headers->url . PHP_EOL;
  echo 'stored date: ' . $response->headers->stored_at . PHP_EOL;
}

$response = $api->get('RID_REPLACE');

echo 'status code: ' . $response->statusCode . PHP_EOL;
if ($response->statusCode === 200) {
  echo 'body: ' . $response->body . PHP_EOL;
  echo 'original status: ' . $response->headers->original_status . PHP_EOL;
  echo 'proxycrawl status: ' . $response->headers->pc_status . PHP_EOL;
  echo 'rid: ' . $response->headers->rid . PHP_EOL;
  echo 'url: ' . $response->headers->url . PHP_EOL;
  echo 'stored date: ' . $response->headers->stored_at . PHP_EOL;
}

if ($api->delete('RID_REPLACE')) {
  echo 'delete success' . PHP_EOL;
  echo 'status code: ' . $api->response->statusCode . PHP_EOL;
} else {
  echo 'delete failed' . PHP_EOL;
  echo 'status code: ' . $api->response->statusCode . PHP_EOL;
}

$items = $api->bulk(['RID1', 'RID2', 'RID3', ...]);
foreach ($items as $item) {
  echo 'body: ' . $item->body . PHP_EOL;
  echo 'stored at: ' . $item->stored_at . PHP_EOL;
  echo 'original status: ' . $item->original_status . PHP_EOL;
  echo 'proxycrawl status: ' . $item->pc_status . PHP_EOL;
  echo 'rid: ' . $item->rid . PHP_EOL;
  echo 'url: ' . $item->url . PHP_EOL;
  echo PHP_EOL;
}

$rids = $api->rids();
foreach ($rids as $rid) {
  echo $rid . PHP_EOL;
}

$rids = $api->rids(10);

$totalCount = $api->totalCount();
echo 'total count: ' . $totalCount . PHP_EOL;