1

I'm trying to parse some html that is inside an external .dat file.

I would normaly use the follwing code:

$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;

But I'm getting this error:

DOMDocument::loadHTMLFile(): htmlParseEntityRef: expecting ';' in http://www.bvl.com.pe/includes/cotizaciones_todas.dat, line: 15

I know that the problem is the loadHTMLFile, I tried using load or loadXML but it's not working neither. Any help would be appriciated.


UPDATE

To solve the problem I had to handle the errors using libxml_use_internal_errors(TRUE). Now I've a new problem, I want to count how many <tr> tags are inside the table. I'm using the following code:

$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);

But I'm getting this error msg: PHP Catchable fatal error: Argument 2 passed to DOMXPath::evaluate() must be an instance of DOMNode, null given I already used the same code with other files and everything worked fine, but in this case it's not working, maybe because the html is broken?

4

0 回答 0