Scraping API Prices
MenuClose

Search the site

91 providers, their alternatives and head-to-heads, targets, guides and answers

Home / Cost tools / cURL converter / PHP

cURL to PHP converter

Paste a cURL command and get the same request in PHP, using PHP's cURL extension. It converts in your browser; nothing you paste is sent anywhere.

Converted in your browser. Nothing you paste is stored or sent, so a command with your API key in it stays on your machine.

PHP, with PHP's cURL extension
<?php

$ch = curl_init('https://api.scraper.example/v1/scrape?url=https%3A%2F%2Fshop.example.com%2Fproducts%3Fpage%3D2&render_js=true&country=us');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
]);

$response = curl_exec($ch);
if ($response === false) {
    echo 'Error: ' . curl_error($ch);
} else {
    echo curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL;
    echo $response;
}
curl_close($ch);

Running the code

It needs PHP's cURL extension, which most PHP installs include. Each curl flag becomes a curl_setopt line, because the extension is libcurl itself.

Where PHP's cURL extension differs from curl

PHP's cURL extension behaves like the curl command: CURLOPT_FOLLOWLOCATION is -L, CURLOPT_ENCODING with an empty string is --compressed, and CURLOPT_TIMEOUT is --max-time in seconds.

What calls like this one cost

The example is a scraping API call with JavaScript rendering on and a country chosen. 100,000 of them a month cost from $49.00 on ScrapeBadger, and the same pages without rendering from $14.99 on FlyByAPIs AI Web Scraper, the cheapest complete bills across 32 web scraping APIs this site prices from their own pages. What rendering adds on each API

The same command in another language