DOMDocument is slow to type and phpQuery has bad memory leak issues. I ended up using:
https://github.com/wasinger/htmlpagedom
To select a class:
include 'includes/simple_html_dom.php';
$doc = str_get_html($html);
$href = $doc->find('.lastPage')[0]->href;
I hope this helps someone else as well