<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>92</id><slug>session-cookies-for-scrapers-part-5-92</slug><title>Session cookies for scrapers, part 5</title><excerpt>In part 5 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>5</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>In part 5 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>Common pitfalls</heading><paragraphs><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><item>Be careful with relative URLs. Resolve every link against the page it came from, not against the site root, or you will request pages that do not exist.</item></paragraphs></item><item><heading>Going further</heading><paragraphs><item>Character encodings still cause trouble. Decode responses using the charset the server declares, and normalise text before comparing or storing it.</item><item>Write small, focused tests for your parsers using saved HTML fixtures. They run in milliseconds and catch layout changes long before a full crawl would.</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>12</authorId><authorName>Yuki Andersson</authorName><authorSlug>yuki-andersson</authorSlug><category>Scraping Basics</category><tags><item>ethics</item><item>javascript</item><item>scrapy</item></tags><publishedAt>2023-11-30T00:00:00.000Z</publishedAt><wordCount>171</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
