<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>132</id><slug>session-cookies-for-scrapers-part-7-132</slug><title>Session cookies for scrapers, part 7</title><excerpt>For part 7, we revisit the basics with a fresh example and a few lessons learned the hard way. 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>7</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>For part 7, we revisit the basics with a fresh example and a few lessons learned the hard way. 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>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><item>Time zones matter more than they seem. Store timestamps in UTC and convert only when displaying them.</item></paragraphs></item><item><heading>A practical approach</heading><paragraphs><item>Log every request with its URL, status code and duration. When something goes wrong at two in the morning, those logs are the difference between a quick fix and a long investigation.</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></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>6</authorId><authorName>Sofia Fischer</authorName><authorSlug>sofia-fischer</authorSlug><category>Scraping Basics</category><tags><item>playwright</item><item>testing</item></tags><publishedAt>2024-04-13T00:00:00.000Z</publishedAt><wordCount>171</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
