Glossary
Cookie: the state a site keeps in your client
A cookie is a small named value that a server sets with a Set-Cookie header and the client sends back on later requests, letting a stateless protocol remember who you are.
How cookies work
HTTP itself has no memory between requests. Cookies add it. The server sends Set-Cookie: session=abc123; Path=/; Secure; HttpOnly, the client stores it, and every later request to a matching URL carries Cookie: session=abc123. Browsers handle this automatically; HTTP libraries do it when you use a session object or a cookie jar.
Attributes that decide when a cookie is sent
- Domain and Path: which hosts and paths receive it.
- Expires or Max-Age: when it dies. Without either, it is a session cookie that lasts until the browser closes.
- Secure: only sent over HTTPS.
- HttpOnly: hidden from page JavaScript.
- SameSite: whether it goes along with cross site requests (Strict, Lax or None).
If a cookie seems to vanish in your scraper, check these first: a domain mismatch (www versus the bare domain) or a Secure cookie on an http URL are the usual culprits.
Session cookies
Most sites issue a session identifier on the first visit and tie everything to it: language, cart, consent choices and bot scores. Keep one cookie jar per logical visitor and reuse it across that visitor's requests, together with a sticky session on the proxy side. Starting a fresh session for each request throws away whatever trust the session had earned and often triggers more checks, not fewer.
Clearance cookies
Bot protection layers commonly prove a passed check with a cookie rather than a token in the form.
| Cookie | Issued by | Task that provides it |
|---|---|---|
cf_clearance | Cloudflare's full page browser check | Cloudflare Challenge |
aws-waf-token | An AWS WAF check, silent or visual | AWS WAF |
datadome | DataDome protection | DataDome Slider |
These cookies are bound to the context that earned them. A cf_clearance cookie, for instance, only works from the same IP and with the same user agent, which is why the Cloudflare challenge task requires your proxy and returns the user agent to use (see cf_clearance). A clearance cookie typically takes under 10 seconds to obtain.
Reusing cookies well
import requests
jar_session = requests.Session()
jar_session.proxies = {"https": "http://user:pass@203.0.113.7:8080"}
jar_session.headers["User-Agent"] = solution["userAgent"]
jar_session.cookies.set("cf_clearance", solution["cookies"]["cf_clearance"],
domain=".example.com", path="/")
first = jar_session.get("https://example.com/catalog", timeout=30)
Reuse a clearance cookie for as long as the site accepts it, rather than solving again for every page. When it stops working (the challenge returns), solve once more. This keeps costs down, since each solve is billed only when it succeeds, and it is gentler on the site. The cf_clearance reuse guide covers the details.
Cookies and privacy
Cookies can identify people, so in many jurisdictions sites must ask for consent before setting non essential ones (see GDPR and scraping). For scraping, store only the cookies you need for the session and discard them when the job ends.
Common questions
What is the difference between a session cookie and a persistent cookie?
A session cookie has no expiry and ends with the browser session; a persistent cookie lives until its Expires or Max-Age date.
Why does my scraper lose its cookies?
Often the client has no cookie jar, or the cookie domain, path or Secure flag does not match the URL you call.
What is a clearance cookie?
A cookie that bot protection sets after a passed check, such as cf_clearance, so later requests skip the challenge.
Can I use a cf_clearance cookie from another IP?
No. It is bound to the IP and user agent that earned it, so use the same proxy and user agent.
How long should I reuse a clearance cookie?
Until the site stops accepting it and the challenge returns. Then solve once more and continue.
Keep reading
- cf_clearance cookieThe cookie Cloudflare sets after a passed challenge, why it only works from one IP and user agent, and its lifespan.
- Reusing cf_clearance cookies safelyDesign sessions around cf_clearance: bind each cookie to one IP and user agent, track its age and refresh only when needed.
- Sticky sessionA sticky session pins one exit IP for a while, so cookies and CAPTCHA answers earned on that address keep working.
- Cloudflare Challenge solver$0.84 per 1,000 tasks, answers under 10 seconds.