I make these for myself all the time.
I do one-offs in sed and if it is something I will reuse I redo it in C using flex.
If you want something generalized to all web pages that removes google analytics, doubleclick, scorecardresearch, etc. of course that is possible too. I am happy to make this for anyone who wants it.
Another solution is to run a proxy on your computer that filters out garbage. Such proxies used to be more popular when advertising began to take over the web, but most of these projects seem to have been abandoned and forgotten (junkbusters, etc.).
Nowadays it seems like people try to accomplish this via Javascript running in the browser.
Turning off Javascript is also highly effective at disabling advertising. But note this may not stop things like img src tags pointing at tracking pixels, malicious iframes, and other elements that graphical browsers will load automatically.
Also, tcp clients do not normally store or send cookies. And even if they try to provide this functionality, e.g., curl or wget, unlike a graphical web browser, cookies are off by default. Consider the case where the user retrieves the page with a tcp client and then views it in a browser.
For each use case that is not a free browsing I create an electron app, that never executes any code from the web or uses any external style. It only uses XHR to fetch html pages/json data/other static stuff and then transforms that data and uses it in the custom UI designed for the use case.
That's what I was thinking; a proxy server that can run on a pi. Plug it into the wall, configure wifi, connect to it, and bam - instant safety. (Assuming you trust the code.)