doushi7819 2015-04-10 07:09
浏览 52
已采纳

使用PHP Simple HTML DOM解析器时出错

    if (!is_null($elements)) {          

        $embeds = array();
        foreach ($elements as $element) {

            if (trim(strip_tags($element->innertext)) == $episode_term) {
                $html2 = file_get_html($element->href);
                $elements2 = $html2->find('#streamlinks .sideleft a');
                if (!is_null($elements2)) {
                    foreach ($elements2 as $element) {
                        $html3 = file_get_html($element->href);
                        $iframe_element = $html3->find('.frame', 0);
                        if (!is_null($iframe_element)) {
                            $embed = $misc->buildEmbed($iframe_element->src);
                            if ($embed) {
                                $embeds[] = array(
                                    "embed" => $embed,
                                    "link" => $iframe_element->src,
                                    "language" => "ENG",
                                );
                            }
                        }
                    }                        
                }
            }
        }
        return $embeds;
    }

Blockquote PHP Fatal error: Call to a member function find() on a non-object in

                $elements2 = $html2->find('#streamlinks .sideleft a');

so its confusing as to what is causing this error to appear in my error log file?

  • 写回答

1条回答 默认 最新

  • doulianglou0898 2015-04-10 07:22
    关注

    I'd try to output $element->href befor you do the file_get_html. If the file_get_html can't get a page $html2 stays uniinitialized and you can't use find on it.

    Beside that you could build a check wether $html2 is set after the file_get_html and output an error if not. I usually use something like this:

    if($html2 == false || $html2 == NULL){
      // no html found
    }else{
      // html found
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳