Developers

Web Scraping API

Reference

Headers, cookies and method

Configure HTTP request context sent to the target page.

Custom headers

Place target headers in a headers context entry and enable force_headers. These values belong to the target request. API authentication stays on your outer request to Crawlhub.

Header context
{
  "source": "universal",
  "url": "https://example.com/",
  "context": [
    {
      "key": "force_headers",
      "value": true
    },
    {
      "key": "headers",
      "value": {
        "Accept-Language": "en-US,en;q=0.8"
      }
    }
  ]
}

Custom cookies

Provide a cookies array of key/value objects and force_cookies: true inside context. Combine cookies with session_id if related jobs need the same proxy session.

Cookie context
{
  "source": "universal",
  "url": "https://example.com/",
  "context": [
    {
      "key": "force_cookies",
      "value": true
    },
    {
      "key": "cookies",
      "value": [
        {
          "key": "region",
          "value": "us"
        }
      ]
    }
  ]
}

POST to a target

The universal source uses GET by default. To POST to the target, set http_method to post and pass the Base64-encoded body in content. Both are context entries. The API submission itself is still a POST JSON request.

Target POST with hello=world
{
  "source": "universal",
  "url": "https://httpbin.org/post",
  "context": [
    {
      "key": "http_method",
      "value": "post"
    },
    {
      "key": "content",
      "value": "aGVsbG89d29ybGQ="
    }
  ]
}

Redirects and accepted status

The follow_redirects context switch controls redirect following; the default follows up to 10 redirects as one job. Use successful_status_codes only when a nonstandard target status is an intentional collection result.

Search documentation

Search guides, products and reference pages.