This might sound a bit complicated, but what I want to do is find all <a>
s that contain <img>
s such that the images that are in the same node with the greatest number of other images are chosen first.
For example, if my page looks like this:
If the blue squares are <div>
s and the pink squares are <img>
s then the middle div
contains the most images, then those images are chosen first. Since they aren't nested any deeper than that, they are just appear in the order that they are on the page. Next the first div is chosen (contains the 2nd most images), and so forth... does that make sense?
We can think of it sort of recursively. First the body
would be chosen since that will always contain the most images, then each of the direct children are examined to see which contains the most image descendants (not necessarily direct), then we go into that node, and repeat...