简单的HTML DOM适用于一个URL,但不适用于其他URL

时间:2017-01-31 14:56:29

标签: php simple-html-dom

我的代码如下:

只有在我浏览一个网页时才有效。

<?php
   include_once('simple_html_dom.php');
   echo '<table border=1px>';
    for ($x = 1; $x <= 2; $x++) {
        $target_url = 'http://www.example.com/movie.php?movieid='.$x;
        $html = new simple_html_dom();
        $html->load_file($target_url);
        echo '<tr>';
            foreach($html->find('div.movieboxsright') as $div){
                foreach($div->find('div[class=bl_tle_mvi blue_tlte]') as $title){
                    echo '<td>'.$title->find('a')[0]->innertext.'</td>';
                }
                foreach($div->find('div[class=movieboxssec]') as $details){
                    echo '<td>'.$details->find('span[style=border:1px solid #c61a17; margin:0px 4px;]',0)->innertext.'</td>';

                }
            }

        echo '</tr>';
    }
echo '</table>';
?>

我得到的错误是:在第1113行的/Library/WebServer/Documents/simple_html_dom.php中调用null上的成员函数find()

我试图检查错误的位置,它出现在我试图找到具有特定样式的span元素的最后一行。我已经检查了我想要访问的网站,这两个页面上都有这个标签。

0 个答案:

没有答案