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

Sending Custom Headers

You can send custom headers (User Agent, Referer, Cookies, etc.) when making a request through our API. By addin the keep_headers=true parameter, the API will forward these headers to the target website.

  • API REQUEST

curl --request GET \
  --header "X-MyHeader: 123" \
  --url 'http://api.scraperapi.com/?api_key=API_KEY&keep_headers=true&url=http://example.com' 
import requests

target_url = 'https://example.com'
# Replace the value for api_key with your actual API Key.
api_key = 'API_KEY'
headers = {
    'X-MyHeader': '123'
}

request_url = (
    f'http://api.scraperapi.com?'
    f'api_key={api_key}'
    f'&url={target_url}'
    f'&keep_headers=true'
)

response = requests.get(request_url, headers=headers)
print(response.text)
  • PROXY MODE

curl --request GET \
  --header "X-MyHeader: 123" \
  --proxy "http://scraperapi.keep_headers=true:API_KEY@proxy-server.scraperapi.com:8001" \ 
  --insecure \
  "http://example.com"
import requests

target_url = 'https://example.com'
# Replace the value for api_key with your actual API Key.
api_key = 'API_KEY'

headers = {
    'X-MyHeader': '123'
}

proxies = {
    'http': f'http://scraperapi.keep_headers=true:{api_key}@proxy-server.scraperapi.com:8001'
}

response = requests.get(
    target_url,
    headers=headers,
    proxies=proxies,
    verify=False
)

print(response.text)

Last updated