<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>112</id><slug>session-cookies-for-scrapers-part-6-112</slug><title>Session cookies for scrapers, part 6</title><excerpt>Part 6 looks at what changes when the same technique has to run every day in production. Logging in once and staying logged in is a matter of keeping the cookies the server gives you and sending them…</excerpt><seriesName>Session cookies for scrapers</seriesName><seriesPart>6</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>Part 6 looks at what changes when the same technique has to run every day in production. 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>Putting it into practice</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>Treat HTTP 429 responses as a signal, not an obstacle. Read the Retry-After header, back off, and resume at a slower pace.</item><item>Deduplicate as you go. The same item often appears on several listing pages, and a stable identifier such as a SKU or ID makes duplicates easy to spot.</item></paragraphs></item><item><heading>Common pitfalls</heading><paragraphs><item>Dynamic pages render content after the initial HTML arrives. A browser automation tool can wait for a specific element to appear, which is far more reliable than sleeping for a fixed amount of time.</item><item>Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy.</item><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></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>3</authorId><authorName>Priya Nakamura</authorName><authorSlug>priya-nakamura</authorSlug><category>Scraping Basics</category><tags><item>playwright</item><item>testing</item><item>ethics</item><item>json</item></tags><publishedAt>2025-03-25T00:00:00.000Z</publishedAt><wordCount>237</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
