<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>12</id><slug>session-cookies-for-scrapers-12</slug><title>Session cookies for scrapers</title><excerpt>Logging in once and staying logged in is a matter of keeping the cookies the server gives you and sending them back on every later request.</excerpt><seriesName>Session cookies for scrapers</seriesName><seriesPart>1</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>Logging in once and staying logged in is a matter of keeping the cookies the server gives you and sending them back on every later request.</item></paragraphs></item><item><heading>What to watch for</heading><paragraphs><item>Selectors are the most fragile part of any scraper. Prefer stable attributes such as data-testid or semantic structure over generated class names, which can change on every deploy.</item><item>Validate the data you extract. Prices without currencies, dates without time zones and empty fields are common sources of silent errors downstream.</item><item>Character encodings still cause trouble. Decode responses using the charset the server declares, and normalise text before comparing or storing it.</item></paragraphs></item><item><heading>Step by step</heading><paragraphs><item>Always identify your client honestly with a descriptive User-Agent, and keep your request rate modest. A crawler that behaves like a considerate visitor is far less likely to cause problems for the site operator.</item><item>Pagination comes in several shapes: numbered pages, next links, offsets and opaque cursors. Each has trade-offs, and a robust scraper should detect the end of the result set rather than assuming a fixed number of pages.</item><item>Read the site's terms of service before you start. Many sites welcome automated access within limits and say so explicitly; others ask you to use an API instead.</item></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>Use a session object (requests.Session, a Playwright context) for the whole run, and check for redirects to the login page as a sign the session has expired.</item></paragraphs></item></sections><authorId>1</authorId><authorName>Amelia Okafor</authorName><authorSlug>amelia-okafor</authorSlug><category>Scraping Basics</category><tags><item>http</item></tags><publishedAt>2025-06-14T00:00:00.000Z</publishedAt><wordCount>222</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
