{"data":{"id":108,"slug":"working-with-csrf-tokens-part-6-108","title":"Working with CSRF tokens, part 6","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…","seriesName":"Working with CSRF tokens","seriesPart":6,"sections":[{"heading":"Introduction","paragraphs":["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."]},{"heading":"Common pitfalls","paragraphs":["Validate the data you extract. Prices without currencies, dates without time zones and empty fields are common sources of silent errors downstream.","Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy.","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."]},{"heading":"A practical approach","paragraphs":["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.","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."]},{"heading":"Key takeaway","paragraphs":["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."]}],"authorId":4,"authorName":"Lucas Silva","authorSlug":"lucas-silva","category":"Testing","tags":["javascript","playwright","scrapy","testing"],"publishedAt":"2025-04-04T00:00:00.000Z","wordCount":211,"readingTimeMinutes":2}}