Developers

Web Scraping API

Reference

Realtime

Submit one job and receive its content on the same HTTPS connection.

Submit the request

Realtime endpoint
POST https://api.crawlhub.ai/v1/queries

Send your API username and password with HTTP Basic authentication. Use HTTPS and Content-Type: application/json. Your proxy login and dashboard sign-in are separate credentials.

cURL request
: "${CRAWLHUB_USERNAME:?Set your API username}"
: "${CRAWLHUB_PASSWORD:?Set your API password}"

curl --request POST "https://api.crawlhub.ai/v1/queries" \
  --user "$CRAWLHUB_USERNAME:$CRAWLHUB_PASSWORD" \
  --header "Content-Type: application/json" \
  --connect-timeout 15 --max-time 180 \
  --data '{
  "source": "universal",
  "url": "https://example.com/"
}'

Keep the connection open

Realtime holds the request until collection finishes or an error occurs. Configure the client and any intermediate reverse proxy to allow the response to finish. Rendering needs more time, so use a client timeout of 180 seconds.

Python Requests

Python request
import os
import requests

response = requests.post(
    'https://api.crawlhub.ai/v1/queries',
    auth=(os.environ['CRAWLHUB_USERNAME'], os.environ['CRAWLHUB_PASSWORD']),
    json={'source': 'universal', 'url': 'https://example.com/'},
    timeout=(15, 180),
)
response.raise_for_status()
for result in response.json()['results']:
    print(result['status_code'], result['url'])
    print(result['content'])

Node.js

Node.js request
const username = process.env.CRAWLHUB_USERNAME;
const password = process.env.CRAWLHUB_PASSWORD;
if (!username || !password) throw new Error('Set API credentials.');
const response = await fetch("https://api.crawlhub.ai/v1/queries", {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64'),
  },
  body: JSON.stringify({source: 'universal', url: 'https://example.com/'}),
  signal: AbortSignal.timeout(180000),
});
if (!response.ok) throw new Error(`API returned ${response.status}: ${await response.text()}`);
console.log(await response.json());

Larger workloads

Use Push-Pull when your application needs independent submission and retrieval.

Search documentation

Search guides, products and reference pages.