<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>108</id><slug>working-with-csrf-tokens-part-6-108</slug><title>Working with CSRF tokens, part 6</title><excerpt>Part 6 looks at what changes when the same technique has to run every day in production. Cross-site request forgery tokens are one of the first things that trip up a script trying to log in to a…</excerpt><seriesName>Working with CSRF tokens</seriesName><seriesPart>6</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>Part 6 looks at what changes when the same technique has to run every day in production. 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>Common pitfalls</heading><paragraphs><item>Validate the data you extract. Prices without currencies, dates without time zones and empty fields are common sources of silent errors downstream.</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>A practical approach</heading><paragraphs><item>Dynamic pages render content after the initial HTML arrives. A browser automation tool can wait for a specific element to appear, which is far more reliable than sleeping for a fixed amount of time.</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>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>4</authorId><authorName>Lucas Silva</authorName><authorSlug>lucas-silva</authorSlug><category>Testing</category><tags><item>javascript</item><item>playwright</item><item>scrapy</item><item>testing</item></tags><publishedAt>2025-04-04T00:00:00.000Z</publishedAt><wordCount>211</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
