Development Web Scraping Software REST API in php (example)

In this post, I’d like to demonstrate how to leverage the (CloudScrape) API along with its PHP Client library (also avail in Ruby and C#).

There are basically two parameters to initiate API Client: API Key and Account ID. Run ID or Execution ID are to access corresponding parameters.


To get access to your CloudScrape account through an API – you firstly need to create an API key(s) in your account settings:cloudscrape apikey

Account ID

Then you move to the API page (click API tab at the left pane) to view and retrieve you Account ID:

cloudscrape account key

Run ID

To fetch the project’s run ID, just open a corresponding run (Projects left-pane tab and unfold scraper in the view). The picture below shows where to get run ID:

cloudscrape runId

Alternatively to a run ID  you might fetch execution ID – the result of any executed run.

API libraries

To have Access to the API libraries you again travel to API page and click Client libraries.

cloudscrape libraries

To directly download/fork PHP  CloudScrape Client visit here. Download CloudScrape.php and put it onto your server. Then create a PHP file in the same directory where CloudScrape.php is put.


Now let’s put the following PHP code into that file in order to leverage CloudScrape Client functionality. Ready to retrieve some data:

header('Content-type: text/plain');
require_once 'CloudScrape.php';
define('CS_API_KEY','Secret API Key');
define('CS_ACCOUNT_ID','Account Key'); 
$RunId = 'ac78b5c1-c400-45da-b543-315b482696da';  

CloudScrape::init(CS_API_KEY, CS_ACCOUNT_ID);
echo "Run info:" . PHP_EOL ;
$run = CloudScrape::runs()->get($RunId);

echo "Run's all executions (sorted by newest first):";
$execs = CloudScrape::runs()->getExecutions($RunId, $offset, $limit);
foreach($execs->rows as $exec)
	 // for each completed execution we retrieve its data
         if ($exec->state == 'OK') { 
	     print_r($exec) . PHP_EOL . "";
	     echo "Execution details:" . PHP_EOL ;
	     $e = CloudScrape::executions()->getResult($exec->_id);

Sum up

The is the modern web scraping service providing not just point-and-click UI for scrape agents creation but also the REST API in PHP for managing robots, executions and retrieving results. The latter is greatly supported with PHP, Ruby and C# client libraries.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.