1. Go to this page and download the library: Download spidra/spidra-php 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/ */
spidra / spidra-php example snippets
use Spidra\SpidraClient;
$spidra = new SpidraClient('spd_YOUR_API_KEY');
$job = $spidra->scrape->run([
'urls' => [['url' => 'https://news.ycombinator.com']],
'prompt' => 'List the top 5 stories with title, points, and comment count',
'output' => 'json',
]);
print_r($job['result']['content']);
$job = $spidra->scrape->run([
'urls' => [['url' => 'https://example.com/pricing']],
'prompt' => 'Extract all pricing plans with name, price, and
// CSS selector
['type' => 'click', 'selector' => "button[data-testid='submit']"]
// Plain English — AI finds the element
['type' => 'click', 'value' => 'Accept all cookies button']
// Type into a field
['type' => 'type', 'selector' => "input[name='q']", 'value' => 'wireless headphones']
// Wait for content to load
['type' => 'wait', 'duration' => 2000]
// Scroll to bottom
['type' => 'scroll', 'to' => '100%']
$job = $spidra->scrape->run([
'urls' => [
[
'url' => 'https://books.toscrape.com/catalogue/category/books/mystery_3/index.html',
'actions' => [
[
'type' => 'forEach',
'observe' => 'Find all book cards in the product grid',
'mode' => 'inline',
'captureSelector' => 'article.product_pod',
'maxItems' => 20,
'itemPrompt' => 'Extract title, price, and star rating. Return as JSON: {title, price, star_rating}',
],
],
],
],
'prompt' => 'Return a clean JSON array of all books',
'output' => 'json',
]);
[
'type' => 'forEach',
'observe' => 'Find all book title links in the product grid',
'mode' => 'navigate',
'captureSelector' => 'article.product_page',
'maxItems' => 10,
'waitAfterClick' => 800,
'itemPrompt' => 'Extract title, price, star rating, and availability. Return as JSON.',
]
[
'type' => 'forEach',
'observe' => 'Find all room type cards',
'mode' => 'click',
'captureSelector' => "[role='dialog']",
'maxItems' => 8,
'waitAfterClick' => 1200,
'itemPrompt' => 'Extract room name, bed type, price per night, and amenities. Return as JSON.',
]
[
'type' => 'forEach',
'observe' => 'Find all book title links',
'mode' => 'navigate',
'maxItems' => 40,
'pagination' => [
'nextSelector' => 'li.next > a',
'maxPages' => 3, // 3 additional pages beyond the first
],
]
[
'type' => 'forEach',
'observe' => 'Find all book title links',
'mode' => 'navigate',
'captureSelector' => 'article.product_page',
'maxItems' => 5,
'waitAfterClick' => 1000,
'actions' => [
['type' => 'scroll', 'to' => '50%'],
],
'itemPrompt' => 'Extract title, price, and full description. Return as JSON.',
]
// Submit a job and get the jobId immediately
$queued = $spidra->scrape->submit([
'urls' => [['url' => 'https://example.com/listings']],
'prompt' => 'Extract all property listings',
'output' => 'json',
]);
$jobId = $queued['jobId'];
// Check status at any point
$result = $spidra->scrape->get($jobId);
if ($result['status'] === 'completed') {
print_r($result['result']['content']);
} elseif ($result['status'] === 'failed') {
echo $result['error'];
}
$job = $spidra->scrape->run(
params: [...],
timeout: 180, // wait up to 3 minutes
pollInterval: 5, // check every 5 seconds
);
$job = $spidra->crawl->run([
'baseUrl' => 'https://competitor.com/blog',
'crawlInstruction' => 'Find all blog posts published in 2024',
'transformInstruction' => 'Extract the title, author, publish date, and a one-sentence summary',
'maxPages' => 30,
'useProxy' => true,
]);
foreach ($job['result'] as $page) {
echo $page['url'] . "\n";
print_r($page['data']);
}
$queued = $spidra->crawl->submit([
'baseUrl' => 'https://example.com/docs',
'crawlInstruction' => 'Find all documentation pages',
'transformInstruction' => 'Extract the page title and main content summary',
'maxPages' => 50,
]);
$jobId = $queued['jobId'];
// Check status later
$status = $spidra->crawl->get($jobId);
$result = $spidra->crawl->pages($jobId);
foreach ($result['pages'] as $page) {
echo $page['url'] . ' — ' . $page['status'] . "\n";
// $page['html_url'] — download raw HTML
// $page['markdown_url'] — download markdown
}
$newJob = $spidra->crawl->extract(
$sourceJobId,
'Extract only the product SKUs and prices as a flat list'
);
// Poll the new job
$result = $spidra->crawl->get($newJob['jobId']);
use Spidra\Exceptions\AuthenticationException;
use Spidra\Exceptions\InsufficientCreditsException;
use Spidra\Exceptions\RateLimitException;
use Spidra\Exceptions\ServerException;
use Spidra\Exceptions\SpidraException;
try {
$job = $spidra->scrape->run([...]);
} catch (AuthenticationException $e) {
// 401 — API key is missing or invalid
echo "Check your API key\n";
} catch (InsufficientCreditsException $e) {
// 403 — monthly credit limit reached
echo "Out of credits. Top up at app.spidra.io\n";
} catch (RateLimitException $e) {
// 429 — too many requests
echo "Rate limited, back off and retry\n";
} catch (ServerException $e) {
// 500 — something went wrong on Spidra's side
echo "Server error, try again\n";
} catch (SpidraException $e) {
// Any other API error
echo "{$e->statusCode}: {$e->getMessage()}\n";
}
$spidra = new SpidraClient(
apiKey: 'spd_YOUR_API_KEY',
baseUrl: 'http://localhost:4321/api', // for local development
);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.