Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 简单HTML DOM解析器错误_Php - Fatal编程技术网

Php 简单HTML DOM解析器错误

Php 简单HTML DOM解析器错误,php,Php,我正在使用PHP简单HTML DOM解析器从10.000多个页面获取电子邮件地址 require_once('simple_html_dom.php'); $html = file_get_html('http://www.myurl'); $email = $html->find('dl', 5)->children(3); 有时会出现跟随错误。可能是因为某些页面没有标签: Fatal error: Call to a member function children() on

我正在使用PHP简单HTML DOM解析器从10.000多个页面获取电子邮件地址

require_once('simple_html_dom.php'); 
$html = file_get_html('http://www.myurl');
$email = $html->find('dl', 5)->children(3);
有时会出现跟随错误。可能是因为某些页面没有标签:

Fatal error: Call to a member function children() on a non-object

如果页面不包含我要查找的信息而不中断整个脚本,如何避免此错误?

如果存在不确定性,请不要链接您的方法。分配
$email=$html->find('dl',5)
-然后测试是否有子项,可能是如果存在不确定性,请不要链接您的方法。分配
$email=$html->find('dl',5)
-然后测试是否有子对象,可能使用您可以使用
is_object()
函数测试
$email
是否为对象,例如

$email = $html->find('dl', 5);
if(is_object($email) === true)
{
    print_r($email->children(3));
}
else continue;

这可能比使用外部库测试儿童要快,因为它使用的是PHP引擎中已有的函数。

您可以使用
is_object()
函数测试
$email
是否为对象,例如

$email = $html->find('dl', 5);
if(is_object($email) === true)
{
    print_r($email->children(3));
}
else continue;
这可能比使用外部库测试子对象要快,因为它使用的是PHP引擎中已经存在的函数。

find()找不到任何东西,所以它返回的没有->children()方法。
find()
找不到任何东西,所以它返回的没有->children()方法。