something which came into my mind, totally unrelated to this PR.

you are doing low-level PHP DOM operations here. Maybe the code would benefit from using a more abstracted API like Symfony DOMCrawler provides. not sure if it has performance impacts though.

https://github.com/symfony/DomCrawler
http://symfony.com/doc/current/components/dom_crawler.html