Introduction
I was working on a project that needed a handful of fields from a real-time data source. The obvious move was a paid data-provider API. Early validation made it clear that was far too expensive, so I did what every cheap software engineer would do: find something slower to build, but cheaper to run.
This led me down a path of exploring increasingly complex ways to extract the same data from a web-based source.
This post is a walkthrough of that evolution: from traditional scraping, to OCR-based extraction with screenshot diffing, and finally to using DOM mutation observers as the simplest reliable solution.
The key lesson was not about scraping itself, but about reframing the problem and gathering important knowledge while iterating.
Attempt 1: Traditional web scraping
The first site I tried was well known for blocking scrapers. After a few days with plain HTTP requests, then a real browser via Playwright, I never got close.
So, I looked for a similar source that was less aggressive. Building a scraper was easy. It worked until the errors started. The site had blocked my VPS. Datacenter IPs were the main reason. A VPN hit the same wall. Sites like this routinely flag hosting ranges, so even a working scraper would keep dying. The potential solution was rented residential proxies or rotating infrastructure which I wanted to avoid because I'd have to pay for those and I was not even sure it would work. That felt like a bad longterm solution for an MVP that wasn't earning money yet.
Attempt 2: OCR-based extraction with screenshot diffing
I remembered a project that used OCR (optical character recognition - turning images of text into actual text) and wondered if that could bypass the scraping problem entirely.
I started by screenshotting the values I cared about and feeding them into Tesseract from the CLI. The results were inconsistent. The first fix was font and colour: I looked up what Tesseract handled well, then built a small Chrome extension that restyled the target area to black and white and swapped in that font. Accuracy jumped to a satisfying level.
Once that worked, I built a simple Electron app. The user opened a small window, dragged it over the region to "scrape," and hit start. Under the hood it periodically captured that screen region, ran OCR, and compared the text to the previous result. On change, it forwarded the data to the service that needed it.
Latency was the next problem. OCR could take a few seconds, which was unacceptable here. My first mistake was writing screenshots to disk. The fix was screenshot diffing: keep the previous crop in memory, compare each new capture to it, and only run OCR when the image actually changed. Matching frames meant skip OCR and skip the update. The crop comparison ran every 100ms (ten checks a second) which was good enough for now.
It was an interesting project, and it worked for a while. Then the product needed multiple regions across multiple pages, and the margin for error got huge. Move the original window, or open another browser window on top of it, and the app would silently break OCRing whatever happened to sit under the capture zone.
There were ways I could have solved that but I didn't think it was worth it and I ultimately went back to the drawing board.
Attempt 3: Back to scraping with a better source
While the OCR app was barely managing with the needs, I kept looking into different scrapable data sources and APIs that could be paid. I had a meeting with a few companies that asked for abnormal amounts of monthly payments to get the data that I needed. Paying that while the product is still not earning any money was out of the question.
I stumbled upon one website that had acceptable latency and weaker bot protection than the ones from attempt 1. That was ideal because I wouldn't have to jump through hoops in order to get the data I wanted. The remaining question was how to observe the updates efficiently and not cause any IP blocking. That led to mutation observers.
One caveat: scraping can conflict with a site's terms of service, so I kept the footprint small and only ever saw this as a bridge until the MVP could afford a licensed feed.
Final approach: DOM mutation observers
The setup was a small Node.js service with in-memory state, Playwright driving a headless browser, and MutationObservers on the nodes that held the fields I needed. Instead of requesting the page over and over, I loaded it once and subscribed to changes. When a value updated in the DOM, the observer fired and I forwarded that update downstream. Same data problem as before, much less work per change and much faster than OCR or re-fetching the page many times a second.
While building that, I noticed some of those sources were pushing updates over WebSockets. When that was available, it was the better path: attach a listener through Playwright and work with the payloads directly instead of parsing HTML. Observers covered the DOM case; WebSockets were the upgrade when the site offered them.
Compared with the OCR app with its screen crops every 100ms, multi second Tesseract runs, silent breakage when a window moved, this was far simpler and delivered the most value: one browser session, updates only when the page actually changed, and no fragile capture zones to worry about.
I've come to an ideal replacement for a paid service until the MVP proves it's worth. The simplest solution often appears only after exploring overly complex ones and coming back to the drawing board with a fresh mind and knowledge that was built with multiple attempts at solving the issue.