简单的html dom无法正常工作,显示错误[关闭]

问题描述:

I am using simple html dom to parse html page..... This is my code..

include('simple_html_dom.php');


$html = file_get_html($my_url);


foreach($html->find('div') as $ul) {
     echo $ul;
   }

And i have also tried many other ways . Still i get this error. Error:

 Call to a member function find() on a non-object

I have tried out with other tags as well...

  $html->find('a');
  $html->find('h3');
  //But still same above error

Can anyone plz help me out wit the error..Thanks in advance

我使用简单的html dom来解析html页面..... 这是我的代码.. p>

  include('simple_html_dom.php'); 
 
 
 $ html = file_get_html($ my_url); 
 
 
foreach($ html-> find(  'div')$ ul){
 echo $ ul; 
} 
  code>  pre> 
 
 

我还尝试了很多其他方法。 我仍然收到此错误。 错误: p>

 在非对象上调用成员函数find()
  code>  pre> 
 
  

我也试过了其他标签... p>

  $ html-> find('a'); 
 $ html-> find(  'h3'); 
 //但仍然同上面的错误
   code>  pre> 
 
 

任何人都可以帮助我解决错误。提前谢谢 p> \ n div>

Well i found out the solution, The solution is:-

The latest version of simple_html_dom has got bugs in it.... So dont use simplehtmldom_1_5 file from sourceforge... Better use simplehtmldom_1_10 from sourceforge it works fine.

Bugs in simplehtmldom_1_5:-

Url of any site doesnt work here. You can give url of html file , but site url doesnt work It is not identifying ur object $html after reading the url....

Hope it helps people facing similar problem....

You are using cakephp so you can not use it as like this.

You either need to create vendor( for controller ) or create helper( for view ).

And one more $html is already reserved for $html helper.

For vendor loading

App::import('Vendor', 'HTMLDOM', array('file' => 'HtmlDom' . DS . 'simple_html_dom.php'));

For helper.

App::import('Helper', 'HtmlDom');
$NewHtmlDom = new SimpleHtmlDom; 

$fileContent = $NewHtmlDom->file_get_html($my_url);