【发布时间】:2015-02-19 20:36:26
【问题描述】:
大家好,我正在使用简单的 html dom 获取数据
这是我从网站获取数据的 php 代码 包括('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file($this->main_url.$lin->link);
if($html){
//check if language heading h2 exist then process forward
if($html->find('h2.channel-title',0)){
fetch data from tables
}
}
这一行if($html->find('h2.channel-title',0))在简单html dom的查找功能中找到h2.channel-title在h2.channer-title不存在时给我一个致命错误
在许多页面中<h2 class="channel-title"> English Links</h2> 存在,因此我有根据它们的代码并在我的 foreach 循环中进一步处理它工作正常并获取所有数据。
但是
当<h2 class="channel-title">English Links</h2> 标签不存在时,它会给我一个错误
Fatal error: Call to a member function find() on a non-object in C:\xampp\apps\wordpress\htdocs\wp-content\plugins\autobot\engine\simple_html_dom.php on line 1113
请帮助我,我陷入困境需要帮助,谢谢。我想如果 h2.channel-title 存在运行我的 foreach 代码,否则运行另一个但不要给出错误它停止我的整个脚本。 :(
【问题讨论】:
-
这并没有真正发生,您的代码还有其他问题,但我不知道它是什么。尽量简化。
-
兄弟及以上代码未完成我只给出示例或部分代码给我错误
标签: php simple-html-dom