Sending Custom Headers
IMPORTANT Only use this feature if you need to send custom headers to retrieve specific results from the target website. Within the API, we have a sophisticated header management system designed to increase success rates and performance on difficult sites. When you send your own custom headers you override our header system, which oftentimes lowers your success rates. Unless you absolutely need to send custom headers to get the data you need, we advise that you don’t use this functionality.
Custom headers are not supported when ultra_premium=true is enabled. Even if keep_headers=true is specified, all custom headers will be discarded for ultra-premium-enabled requests.
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:[email protected]: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)PRO TIP:
If you want to get mobile results, you can use the device_type=mobile parameter to set a Mobile User-Agent header for your request, instead of setting it manually yourself.
Last updated

