Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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 从.dat文件解析html_Php_Domdocument - Fatal编程技术网

Php 从.dat文件解析html

Php 从.dat文件解析html,php,domdocument,Php,Domdocument,我试图解析外部.dat文件中的一些html 我通常会使用以下代码: $html = new DOMDocument(); $html->loadHTMLFile('http://www.bvl.com.pe/includes/cotizaciones_todas.dat'); $xpath = new DOMXPath($html); $path = '/somepath'; $nodelist = $xpath->query($path); echo $nodelist->i

我试图解析外部.dat文件中的一些html

我通常会使用以下代码:

$html = new DOMDocument();
$html->loadHTMLFile('http://www.bvl.com.pe/includes/cotizaciones_todas.dat');
$xpath = new DOMXPath($html);
$path = '/somepath';
$nodelist = $xpath->query($path);
echo $nodelist->item(0)->nodeValue;
$html = new DOMDocument();
libxml_use_internal_errors(TRUE);
$html->loadHTMLFile('http://www.bvl.com.pe/includes/cotizaciones_todas.dat');
libxml_clear_errors();
$xpath = new DOMXPath($html);
$tbody = $html->getElementsByTagName('tbody')->item(0);
$path = 'count(tr)';
$trCount = $xpath->evaluate($path,$tbody);
但我得到了一个错误:

DOMDocument::loadHTMLFile(): htmlParseEntityRef: expecting ';' in http://www.bvl.com.pe/includes/cotizaciones_todas.dat, line: 15
我知道问题出在
loadHTMLFile
,我尝试使用
load
loadXML
,但都不起作用。 任何帮助都将受到感谢


更新

为了解决这个问题,我必须使用
libxml\u use\u internal\u errors(TRUE)
处理错误。 现在我有一个新问题,我想计算表中有多少个
标记。我正在使用以下代码:

$html = new DOMDocument();
$html->loadHTMLFile('http://www.bvl.com.pe/includes/cotizaciones_todas.dat');
$xpath = new DOMXPath($html);
$path = '/somepath';
$nodelist = $xpath->query($path);
echo $nodelist->item(0)->nodeValue;
$html = new DOMDocument();
libxml_use_internal_errors(TRUE);
$html->loadHTMLFile('http://www.bvl.com.pe/includes/cotizaciones_todas.dat');
libxml_clear_errors();
$xpath = new DOMXPath($html);
$tbody = $html->getElementsByTagName('tbody')->item(0);
$path = 'count(tr)';
$trCount = $xpath->evaluate($path,$tbody);

但是我得到了这个错误消息:
PHP可捕获致命错误:传递给DOMXPath::evaluate()的参数2必须是DOMNode的一个实例,null给定
我已经在其他文件中使用了相同的代码,并且一切正常,但是在这种情况下它不工作,可能是因为html被破坏了?

查看服务器的错误日志。它将有关于500的更多详细信息。我用日志文件更新了我的帖子。html输出无效(927个错误,1167个警告,根据),请检查投票率最高的答案:@AaronSantos you's right,html被破坏。然而,我现在有一个新的问题(见更新)。