Joe
Joe

Reputation: 205

Problem getting contents of class using php simple dom parser

I can't work out how to get the contents of the second span 'cantfindme' using php simple html dom parser(http://simplehtmldom.sourceforge.net/manual.htm). Using the code below I can get the contents of the first span 'dontneedme'. I cant seem to get anything from second span at all.

$html =  str_get_html('<html><body><table><tr><td class="bar">bar</td><td><div class="foo"><span class="dontneedme">Hello</span></div></td></tr><tr><td class="bar">bar</td><td><div class="foo"><span class="cantfindme">Goodbye</span></div></td></tr></body></html>');
foreach($html->find('.foo', 0) as $article) 
{

    echo "++</br>";
    echo $article->plaintext;
    echo "--</br>";
}

Can anyone see where I'm going wrong?

Upvotes: 0

Views: 1760

Answers (1)

The Pixel Developer
The Pixel Developer

Reputation: 13430

Try using this selector.

$html->find('div.foo .cantfindme');

Check out the documentation for more examples.

Upvotes: 1

Related Questions