Sticky Sessions
To reuse the same proxy across multiple requests, use the session_number parameter by setting it equal to a unique integer for every session you want to maintain (e.g. session_number=123). Requests that share the same session number will continue using the same proxy. To create a new session, simply set the session_number parameter with a new integer to the API. The session value can be any integer. Sessions expire 15 minutes after the last usage.
API REQUEST
curl --request GET \
--url 'https://api.scraperapi.com?api_key=API_KEY&session_number=123&url=https://example.com/'import requests
target_url = 'https://example.com/'
# Replace the value for api_key with your actual API Key.
api_key = 'API_KEY'
request_url = (
f'https://api.scraperapi.com?'
f'api_key={api_key}'
f'&session_number=123'
f'&url={target_url}'
)
response = requests.get(request_url)
print(response.text)import request from 'node-fetch';
// Replace the value for api_key with your actual API Key.
const url = 'http://api.scraperapi.com/?api_key=API_KEY&session_number=123&url=https://example.com/';
request(url)
.then(response => {
console.log(response);
})
.catch(error => {
console.error(error);
});ASYNC REQUEST
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"apiKey": "API_KEY",
"url": "https://example.com/",
"apiParams": {
"session_number": "123"
}
}' \
"https://async.scraperapi.com/jobs"import requests
r = requests.post(
url='https://async.scraperapi.com/jobs',
json={
# Replace the value for api_key with your actual API Key.
'apiKey': 'API_KEY',
'session_number': '123',
'url': 'https://example.com/'
}
)
print(r.text)PROXY MODE
curl --proxy 'http://scraperapi.session_number=123:[email protected]:8001' \
-k \
'https://example.com/'import requests
# Replace the value for api_key with your actual API Key.
proxies = {
"http": "http://scraperapi.session_number=123:[email protected]:8001"
}
r = requests.get('http://example.com/', proxies=proxies, verify=False)
print(r.text)import axios from 'axios';
axios.get('http://example.com/', {
method: 'GET',
proxy: {
host: 'proxy-server.scraperapi.com',
port: 8001,
auth: {
username: 'scraperapi.session_number=123',
// Replace the value for password with your actual API Key.
password: 'API_KEY'
},
protocol: 'http'
}
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.log(error);
});Last updated

