Products / Web Scraping API
Web Scraping API
Send a URL, get the page back. CrawlHub handles proxies, retries and JavaScript rendering, and returns the page's HTML.
i
API credentials are separate from your proxy login and dashboard sign-in. Get them from the product page in the dashboard.
Endpoint and authentication
| Setting | Value |
|---|---|
| Endpoint | POST https://api.crawlhub.ai/v1/queries |
| Authentication | HTTP Basic with your API username and password |
| Request body | JSON, sent with Content-Type: application/json |
| Response | The page's raw HTML |
| Client timeout | 180 seconds. Pages with JavaScript rendering are slower. |
Basic request
Fetch one page. Replace USERNAME and PASSWORD with your API credentials.
curl -X POST https://api.crawlhub.ai/v1/queries \
-u "USERNAME:PASSWORD" \
-H "Content-Type: application/json" \
--max-time 180 \
-d '{"source":"universal","url":"https://example.com/"}'import requests
payload = {
"source": "universal",
"url": "https://example.com/"
}
response = requests.post(
"https://api.crawlhub.ai/v1/queries",
auth=("USERNAME", "PASSWORD"),
json=payload,
timeout=180,
)
print(response.text)const payload = {
"source": "universal",
"url": "https://example.com/"
};
const res = 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(payload),
signal: AbortSignal.timeout(180000),
});
console.log(await res.text());<?php
$payload = '{"source":"universal","url":"https://example.com/"}';
$ch = curl_init("https://api.crawlhub.ai/v1/queries");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_USERPWD => "USERNAME:PASSWORD",
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 180,
]);
echo curl_exec($ch);package main
import (
"bytes"
"fmt"
"io"
"net/http"
"time"
)
func main() {
payload := []byte(`{"source":"universal","url":"https://example.com/"}`)
req, _ := http.NewRequest("POST", "https://api.crawlhub.ai/v1/queries", bytes.NewReader(payload))
req.SetBasicAuth("USERNAME", "PASSWORD")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{Timeout: 180 * time.Second}
resp, err := client.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}import java.net.URI;
import java.net.http.*;
import java.time.Duration;
import java.util.Base64;
public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"source": "universal",
"url": "https://example.com/"
}
""";
String auth = Base64.getEncoder().encodeToString("USERNAME:PASSWORD".getBytes());
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.crawlhub.ai/v1/queries"))
.header("Content-Type", "application/json")
.header("Authorization", "Basic " + auth)
.timeout(Duration.ofSeconds(180))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
System.out.println(HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString()).body());
}
}using System.Net.Http.Headers;
using System.Text;
var payload = """
{
"source": "universal",
"url": "https://example.com/"
}
""";
using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(180) };
var auth = Convert.ToBase64String(Encoding.UTF8.GetBytes("USERNAME:PASSWORD"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);
var res = await client.PostAsync("https://api.crawlhub.ai/v1/queries",
new StringContent(payload, Encoding.UTF8, "application/json"));
Console.WriteLine(await res.Content.ReadAsStringAsync());require "net/http"
require "json"
uri = URI("https://api.crawlhub.ai/v1/queries")
req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
req.basic_auth("USERNAME", "PASSWORD")
req.body = {
"source" => "universal",
"url" => "https://example.com/"
}.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 180) do |http|
http.request(req)
end
puts res.bodyExample response
The response body is the page's HTML, exactly as the target returned it.
HTML
<!doctype html>
<html>
<head>
<title>Example Domain</title>
</head>
<body>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents.</p>
</body>
</html>Request parameters
| Parameter | Type | Description |
|---|---|---|
source | string | Required. Use universal. |
url | string | Required. Full target URL. |
geo_location | string | Country for the request, e.g. Germany. See Location & Sessions. |
user_agent_type | string | desktop by default. See User-Agent Presets. |
render | string | html to render JavaScript first. |
browser_instructions | array | Click, type, scroll and wait. Needs render. |
context | array | Headers, cookies, session_id, HTTP method and more. |
callback_url | string | Get notified when an async job is done. |
storage_type / storage_url | string | Deliver async results to your bucket. |
Response
- Body: the page's raw HTML. No JSON wrapper, no parsing.
- HTTP status: tells you if the request worked. See Response Codes.
Integration methods
RealtimeGet the result on the same connection.Push-PullSubmit jobs, poll status, fetch results.Batch RequestsMany URLs in one request.CallbacksGet notified when a job is done.Cloud StorageDeliver results to your bucket.
Features
JavaScript RenderingGet the HTML after JavaScript runs.Browser InstructionsClick, type, scroll and wait.Headers, Cookies & MethodControl the request sent to the target.