Sticky session
A sticky session preserves cookies, local and session storage between requests. To enable this feature, simply set the session
query parameter to the same value between requests. session value must be a string of length between 1 and 512 characters. A session expires after 24 hours since it was last used.
You can also preload localStorage
with preload localStorage or set values dynamically using JS Scenario.
Example
The following example demonstrates how to enable sticky session and preserve cookies between requests to httpbin.org website /coookies
endpoint. In the first request, we set cookie cookie-name
to value cookie-value
. In the second request, we retrieve cookies using the same session which was used in the first request, therefore, we get cookie-name=cookie-value
cookie in the response.
import requests
import json
session_id = "my_session"
payload1 = {
"api_key": "[your API key]",
"url": "https://httpbin.org/cookies",
"cookies": json.dumps([{"name": "cookie-name", "value": "cookie-value"}]),
"session": session_id,
}
response1 = requests.get("https://scraping.narf.ai/api/v1/", params=payload1)
payload2 = {
"api_key": "[your API key]",
"url": "https://httpbin.org/cookies",
"session": session_id,
}
response2 = requests.get("https://scraping.narf.ai/api/v1/", params=payload2)
print(response2.content)
In the second request, httpbin.org/cookies
endpoint returns cookie cookie-name
set in the first request:
{
"cookies": {
"cookie-name": "cookie-value"
}
}