我有这个错误:
Error Trying to get property of non-object
代码是:
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('table');
$rows = $tables->item(0)->getElementsByTagName('tr');
$i=0;
foreach ($rows as $row)
{
/*** get each column by tag name ***/
$cols = $row->getElementsByTagName('td');
$this->data['Table'][$i] = array(
'Attrb1' => $cols->item(0)->nodeValue,
'Attrib2' => $cols->item(1)->nodeValue
);
$i++;
}
}
return $this->toArray();
}
我有这个错误的行是:
'Attrib2' => $cols->item(1)->nodeValue
html代码是:
<table border=1 align="center" cellpadding=5 width="95%">
<!doctype html public "-//w3c//dtd html 4.0//EN">
<html it>
<head>
<meta name="Generator" content="OLS">
</head>
<body>
<td colspan=2 align="center">
<b>
<i>
Attrib1
</i>
</b>
</td>
<td>
<b>
<i>
Attrib2
</i>
</b>
</td>
<td>
<b>
<i>
<tr>
<td>
A000211
</td>
<td nowrap>
Statistic
</td>
</tr>
但我不知道问题出在 foreach 中还是我所做的所有获取数据都是一个大错误,或者我以错误的方式处理 html..所以请帮助我..