<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>48</id><slug>working-with-csrf-tokens-part-3-48</slug><title>Working with CSRF tokens, part 3</title><excerpt>For part 3, we revisit the basics with a fresh example and a few lessons learned the hard way. Cross-site request forgery tokens are one of the first things that trip up a script trying to log in to…</excerpt><seriesName>Working with CSRF tokens</seriesName><seriesPart>3</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>For part 3, we revisit the basics with a fresh example and a few lessons learned the hard way. Cross-site request forgery tokens are one of the first things that trip up a script trying to log in to a site: the form posts fine in a browser but fails with a 403 from code.</item></paragraphs></item><item><heading>What to watch for</heading><paragraphs><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><item>Time zones matter more than they seem. Store timestamps in UTC and convert only when displaying them.</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>Step by step</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>Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy.</item><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></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>Load the form page with a session that keeps cookies, read the hidden token field, and send it back with the same session in the same request.</item></paragraphs></item></sections><authorId>7</authorId><authorName>Kwame Mensah</authorName><authorSlug>kwame-mensah</authorSlug><category>Testing</category><tags><item>http</item><item>selenium</item><item>javascript</item><item>playwright</item></tags><publishedAt>2025-07-22T00:00:00.000Z</publishedAt><wordCount>244</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
