我想从其他网站提取数据,以便根据我网站中的数据网站进行更新,但代码和代码中显示的上述错误如下: -
include('simplehtmldom/simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file("http://www.nepalstock.com/companydetail.php");
$table = $html->find('table[width="386"]');
$i = 0;
$data = array();
foreach ($table[0]->find('tr') as $tr) {<!--this is my line 13-->
$i++;
if ($i == 1 || $i == 2) continue;
$td = $tr->find('td');
array_push($data, array(
'listed_share' => trim($td[0]->plaintext),
'paid_up_value' => trim($td[1]->plaintext),
'total_paid_Up_Value' => trim($td[2]->plaintext),
'closing_market_price' => trim($td[3]->plaintext),
));
}
$html->clear();
unset($html);
if (empty($data)) exit('No data !!!');
print '<pre>';
print_r($data);
print '</pre>';
答案 0 :(得分:0)
当您使用实际不存在的对象时,通常会发生此错误。尝试更改下面的代码,并记住在处理外来内容时特别保留此编码行为:
if (!empty($html){
$table = $html->find('table[width="386"]');
if(!empty($table)){
...