{"data":{"id":98,"slug":"headless-vs-headed-browsers-part-5-98","title":"Headless vs headed browsers, part 5","excerpt":"For part 5, we revisit the basics with a fresh example and a few lessons learned the hard way. Running a browser without a window is faster and works on servers, but some problems are much easier to…","seriesName":"Headless vs headed browsers","seriesPart":5,"sections":[{"heading":"Introduction","paragraphs":["For part 5, we revisit the basics with a fresh example and a few lessons learned the hard way. Running a browser without a window is faster and works on servers, but some problems are much easier to understand when you can watch the browser do its work."]},{"heading":"What to watch for","paragraphs":["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.","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":"Putting it into practice","paragraphs":["Selectors are the most fragile part of any scraper. Prefer stable attributes such as data-testid or semantic structure over generated class names, which can change on every deploy.","Treat HTTP 429 responses as a signal, not an obstacle. Read the Retry-After header, back off, and resume at a slower pace."]},{"heading":"Key takeaway","paragraphs":["Develop headed with slow motion turned on, run headless in CI, and capture screenshots or traces on failure so headless runs are still debuggable."]}],"authorId":4,"authorName":"Lucas Silva","authorSlug":"lucas-silva","category":"Browser Automation","tags":["ethics","testing","selenium","json"],"publishedAt":"2023-10-29T00:00:00.000Z","wordCount":210,"readingTimeMinutes":2}}