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?

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.