我让PHP AdvancedHTMLDOM工作了很长时间。但是,大约一周前,我注意到由于某些原因,我正在抓取的数据没有得到更新。
我手动运行了脚本,并出现以下错误:
root@telemetry:/home/telemetry/scripts/pressure# php -f get_pressure_nodes.php
PHP Fatal error: Uncaught Error: Class 'DOMDocument' not found in /home/telemetry/scripts/pressure/advanced_html_dom-master/advanced_html_dom.php:171
Stack trace:
#0 /home/telemetry/scripts/pressure/advanced_html_dom-master/advanced_html_dom.php(167): AdvancedHtmlDom->load('<html>\n<head>\n<...', false)
#1 /home/telemetry/scripts/pressure/advanced_html_dom-master/advanced_html_dom.php(747): AdvancedHtmlDom->__construct('<html>\n<head>\n<...')
#2 /home/telemetry/scripts/pressure/advanced_html_dom-master/advanced_html_dom.php(748): str_get_html('<html>\n<head>\n<...')
#3 /home/telemetry/scripts/pressure/get_pressure_nodes.php(17): file_get_html('get_pressure_no...')
#4 {main}
thrown in /home/telemetry/scripts/pressure/advanced_html_dom-master/advanced_html_dom.php on line 171
root@telemetry:/home/telemetry/scripts/pressure#
这是我的脚本(为了简单起见,我保留了基础知识,我也从无法回忆的地方获得了此代码,因此,如果是您的,请通知我,以便在适当的时候提供帮助)
<?php
require('advanced_html_dom-master/advanced_html_dom.php');
$html = file_get_html('get_pressure_nodes.html');
$table = $html->find('table', 1);
$rowData = array();
foreach($table->find('tr') as $row)
{
// initialize array to store the cell data from each row
$temp = array();
foreach($row->find('td') as $cell)
{
// push the cell's text to the array
$temp[] = $cell->plaintext;
}
$rowData[] = $temp;
}
foreach ( $rowData as $cell_contents )
{
print ( $cell_contents ) ;
}
?>