Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Scraping

Scrapes a web page, Google search results, or an image, and returns the content.

POST /v1/scrape

Each successful request costs one credit.

Request Body

Parameter
Type
Required
Description

source

string

Yes

What to scrape: universal, google, or image

url

string

For universal and image

The full target URL, starting with http:// or https://. Up to 2,048 characters.

query

string

For google

The search keywords. Cannot be empty. Up to 500 characters.

geo_location

string

No

Two-letter country code in the ISO 3166-1 alpha-2 format, such as us or de. Not case-sensitive. See Supported Countries.

parse

boolean

No

For universal only. Set to true to receive structured JSON instead of HTML. Defaults to false.

Send only the fields your source uses. Fields not listed here are ignored.

curl -X POST https://scrape.iproyal.com/v1/scrape \
  -H "Authorization: Bearer $WEB_SCRAPER_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"source": "universal", "url": "https://example.com"}' \
  --max-time 90
<?php

$ch = curl_init('https://scrape.iproyal.com/v1/scrape');

curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 90,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('WEB_SCRAPER_API_TOKEN'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'source' => 'universal',
        'url' => 'https://example.com',
    ]),
]);

$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($status === 200) {
    $result = $body['results'][0];
    echo $result['status_code'] . ' ' . $result['job_id'] . PHP_EOL;
    $html = $result['content'];
} else {
    echo $status . ' ' . $body['error']['code'] . ': ' . $body['error']['message'] . PHP_EOL;
}

Sources

Web Page (universal)

Returns any public web page. Pages load in a real browser, so content that JavaScript adds is included. content holds the page HTML as a string.

Structured Data

Set parse to true, and IPRoyal extracts structured data from the page. content then holds a JSON object instead of HTML. Its structure depends on the page.

If the page has no structured data to extract, the request fails with 422 no_data_extracted and is not charged. Retry without parse to get the HTML.

parse works only with universal. Sending it with another source returns 400 invalid_request.

Google Search (google)

Returns one page of Google search results. content holds the results as a JSON object, and url in the response is null.

Use geo_location to see the results a searcher in that country would see.

Image (image)

Downloads an image from its URL. Use it for images that a website does not let you download directly. It does not take screenshots of web pages.

Use geo_location to download the image as a visitor from that country.

content holds the image file as a Base64 string. Decode it to get the file. The cURL example uses jq.

If the page at the URL has no image, the request fails with 404 not_found and is not charged.

Response

Field
Type
Description

results

array

The result of the request. It always holds one item.

content

string or object

HTML string for universal, JSON object for universal with parse and for google, Base64 string for image

created_at

string

When processing started, in UTC, as YYYY-MM-DD HH:MM:SS

updated_at

string

When processing finished, in UTC

page

integer

Always 1

url

string or null

The URL you requested. null for google.

job_id

string

Unique ID of the request. The same ID appears in Usage History.

status_code

integer

The HTTP status the target website returned

When the Target Page Does Not Exist

If the target website answers with 404 or 410, IPRoyal still delivers its page. You receive HTTP 200, and status_code shows 404 or 410. The request is charged, because the page was retrieved.

Check status_code before you use content.

Response Time

Response time depends on the target website. In rare cases, a request takes up to 75 seconds. Set your HTTP client timeout to at least 90 seconds.

Errors

HTTP Status

error.code

When

400

invalid_request

A field is missing or not valid

401

invalid_token

The token is missing or not recognized

402

insufficient_credit

Your credit balance is empty

403

account_suspended or account_disabled

Your account cannot make requests

404

not_found

No image was found at the URL (image only)

413

payload_too_large

The request body is larger than 100 KB

422

blocked

The target website blocked the request

422

no_data_extracted

parse found no structured data

429

concurrency_limit_exceeded

Too many of your scrape requests are running at once

500 or 503

internal_error

A temporary problem on IPRoyal's side

502

upstream_unavailable

The scrape could not be completed

503

capacity_exceeded

The service is at full capacity

Requests that end in an error are not charged. API explains what to do for each code.

Last updated

Was this helpful?