Ask HN: How to locate ads on websites programmatically?

2 points by InGodsName ↗ HN
Let's say if i want to screenshot the ad banners which appear on the website. How can i do this?

The challenge is the determine what is a banner programmatically.

What technology can be used for this?

6 comments

[ 551 ms ] story [ 167 ms ] thread
What are you using to fetch the pages? Something like CasperJS/PhantomJS? If the banners are images or iframes from an external domain you should be able to traverse the DOM and locate them this way. You would have to have a list of ad providers domains to look for and you might miss some.
Modify an ad-blocker to instead of blocking highlight ads?
Nice idea! Is there any resource on how modern ad blockers detect and block ad banners?
As greenyoda suggested, I'd start with source and documentation of uBlock. From what I know, the major blockers share the format for their blocklists. There's two types of blocks: visual blocks, which contain a CSS selector to hide, and network blocks. Since the latter commonly block scripts that load ad elements, you'd probably need to load the page twice, to observe what elements are not created when the ad-scripts are blocked.