开发者

Parsing HTML: Call to a member function > children() on a non-object

I was just helped with this question but I can't get it to move to the next block of HTML.

$html = file_get_html('http://music.banadir24.com/singer/aasha_abdoo/247.html');

$urls = $html->find('table[width=100%] table tr');

foreach($urls as $url){

     $song_name = $url->children(2)->plaintext;

     $url = $url->children(6)->children(0)->href;   

}

It returns the list of the names of the first album (Deesco) but it does not continue to the next album (The Best Of Aasha)? It just gives me this error:

Notice: Trying to get property of non-object in C:\wamp\w开发者_开发技巧ww\test3.php on line 26

Fatal error: Call to a member function children() on a non-object in C:\wamp\www\test3.php on line 28

Why is this and how can I get it to continue to the next table element?

I appreciate any help on this!

Please note: This is legal as the songs are not bound by copyright and they are available to download freely, its just I need to download a lot of them and I can't sit there clicking a button all day. Having said that, its taken me an hour to get this far.


Maybe you'd better write it like this :

foreach($urls as $url){

    if ($node = $url->children(6)) {
        $node->children(0)->href;   
    }

}


The error means that your query for ->children(6) did not return a valid object - presumably because there is no sixth child in that row.

To find out why not, try to debug the returned HTML structure - e.g. using print_r($url).


i think you'll want to refine your selector to include only the tr's of the album names. currently i believe you'll be grabbing all tr's, which could have unexpected results. maybe something like $html->find('table[width=100%] table tr td .title');

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜