duanhunlou7051 2017-03-11 05:37
浏览 51

获取错误尝试在简单的html dom中获取非对象的属性

here is the code which I am using to extract data:

ini_set("user_agent","Opera/9.80 (Windows NT 6.1; U; Edition Campaign 21; en-GB) Presto/2.7.62 Version/11.00");

$html14=file_get_html("https://www.gamesrocket.com/battlefield-1.html");

$title14 = $html14->find('span.price',0)->children(0)->plaintext;

for ($i=0; $i <sizeof($title14) ; $i++) { 
    # code...

    if($title14[$i]){
        echo $title14[$i]->plaintext;
        $a13=$title14[$i]->plaintext;
    }
    else{

        echo "problem";
    }

}

Here I am trying to extract price from the given page but all I am getting this error : Trying to get property of non-object .I am using simple html dom for extracting data

  • 写回答

1条回答 默认 最新

  • dongzhuang2030 2017-03-11 06:11
    关注

    because $title14 is string and not object, you can var_dump($title14); to know the type of it.

    ini_set("user_agent","Opera/9.80 (Windows NT 6.1; U; Edition Campaign 21; en-GB) Presto/2.7.62 Version/11.00");
    
    
    
    $html14=file_get_html("https://www.gamesrocket.com/battlefield-1.html");
    
     $title14 = $html14->find('span.price',0)->children(0)->plaintext;
      for ($i=0; $i <sizeof($title14) ; $i++) { 
    
       if($title14[$i]){
       echo $title14[$i];
       $a13=$title14[$i];
       }
      else{
    
        echo "problem";
    }
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向