Jump to content

DOMDocument -> unable to pull results from href


runnerjp

Recommended Posts

I have been able to pull the html of a given node
<td class="winner">
                <a href="/jockey/497-g-lee">G Lee</a><br><em><a href="/trainer/3372-r-varian">R Varian </a></em>
            </td>

what im trying to do is pull the text if href contains jockey (in this case the result will be G Lee).

im doing this by doing the following

 
@$dom2->loadHTML($trainer);
$xpath2 = new DOMXPath($dom2);
//chekc to see if it had html in it?
                
    
$result_rows2 = $xpath2->query('//a[contains(@href, "jockey")]');
 
note trainer is just the html posted above.


now i do a var_dump on the data and get this:

object(DOMNodeList)#12 (1) { ["length"]=> int(1) } object(DOMNodeList)#13 (1) { ["length"]=> int(1) } object(DOMNodeList)#12 (1) { ["length"]=> int(1) } object(DOMNodeList)#13 (1) { ["length"]=> int(1) } object(DOMNodeList)#12 (1) { ["length"]=> int(1) } object(DOMNodeList)#13 (1) { ["length"]=> int(1) } object(DOMNodeList)#12 (1) { ["length"]=> int(1) }
im not sure why but its not picking up the results?!?!?

would anyone be able to assist?

 

you could try simple_html_dom

include('simple_html_dom.php');

$str = '<td class="winner">
                <a href="/jockey/497-g-lee">G Lee</a><br><em><a href="/trainer/3372-r-varian">R Varian </a></em>
            </td>';
$html = str_get_html($str);
$jockey = $html->find("a[href*=jockey]");
echo $jockey[0];                                             //--> G Lee
$trnr = $html->find("a[href*=trainer]");
echo $trnr[0];                                               //--> R Varian

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.