<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>172</id><slug>session-cookies-for-scrapers-part-9-172</slug><title>Session cookies for scrapers, part 9</title><excerpt>In part 9 we take the ideas from earlier instalments and apply them to a larger, messier site. Logging in once and staying logged in is a matter of keeping the cookies the server gives you and…</excerpt><seriesName>Session cookies for scrapers</seriesName><seriesPart>9</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>In part 9 we take the ideas from earlier instalments and apply them to a larger, messier site. 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>Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy.</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></paragraphs></item><item><heading>What to watch for</heading><paragraphs><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>Store raw responses alongside parsed output while you are developing. When a parser breaks, you can replay the saved HTML instead of hitting the site again.</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>2</authorId><authorName>Noah Bennett</authorName><authorSlug>noah-bennett</authorSlug><category>Scraping Basics</category><tags><item>playwright</item></tags><publishedAt>2025-02-28T00:00:00.000Z</publishedAt><wordCount>176</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
