<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>120</id><slug>when-to-use-an-api-instead-of-scraping-part-6-120</slug><title>When to use an API instead of scraping, part 6</title><excerpt>Part 6 looks at what changes when the same technique has to run every day in production. If a site offers an API for the data you need, scraping its HTML is usually the harder, more fragile and less…</excerpt><seriesName>When to use an API instead of scraping</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. If a site offers an API for the data you need, scraping its HTML is usually the harder, more fragile and less polite option.</item></paragraphs></item><item><heading>Common pitfalls</heading><paragraphs><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><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>Deduplicate as you go. The same item often appears on several listing pages, and a stable identifier such as a SKU or ID makes duplicates easy to spot.</item></paragraphs></item><item><heading>Step by step</heading><paragraphs><item>Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy.</item><item>Write small, focused tests for your parsers using saved HTML fixtures. They run in milliseconds and catch layout changes long before a full crawl would.</item></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>Check for a documented API, a data export or a feed first. Scrape only when none exists, and read the terms of service either way.</item></paragraphs></item></sections><authorId>12</authorId><authorName>Yuki Andersson</authorName><authorSlug>yuki-andersson</authorSlug><category>Ethics &amp; Law</category><tags><item>testing</item><item>playwright</item><item>http</item><item>python</item></tags><publishedAt>2024-10-03T00:00:00.000Z</publishedAt><wordCount>200</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
