{"data":{"id":132,"slug":"session-cookies-for-scrapers-part-7-132","title":"Session cookies for scrapers, part 7","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…","seriesName":"Session cookies for scrapers","seriesPart":7,"sections":[{"heading":"Introduction","paragraphs":["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."]},{"heading":"What to watch for","paragraphs":["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.","Time zones matter more than they seem. Store timestamps in UTC and convert only when displaying them."]},{"heading":"A practical approach","paragraphs":["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.","Validate the data you extract. Prices without currencies, dates without time zones and empty fields are common sources of silent errors downstream."]},{"heading":"Key takeaway","paragraphs":["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."]}],"authorId":6,"authorName":"Sofia Fischer","authorSlug":"sofia-fischer","category":"Scraping Basics","tags":["playwright","testing"],"publishedAt":"2024-04-13T00:00:00.000Z","wordCount":171,"readingTimeMinutes":2}}