How do you avoid this becoming horrendously expensive per run? Are the results cached if the DOM doesn't change?
Some minimal model that could be run locally and specifically tuned for this purpose might be pretty fruitful here compared to delegating out to expensive APIs.