2
A while ago I asked a question about regular expressions and a user answered me using this code, using xpath
:
$dom = new DomDocument;
$dom->loadHTMLFile("http://ciagri.iea.sp.gov.br/precosdiarios/");
$xpath = new DomXPath($dom);
// essa query pega o todos os TDs na posicao 3 da primeira tabela com a classe
$nodes = $xpath->query("(//table[@class='tabela_dados'])[1]/tr/td[position()=3]");
foreach ($nodes as $i => $node) {
echo $node->nodeValue . "\n"; // vai imprimir todos os preços
}
In the documentation of xpath
the description of how the data of the "nodes" are stored has not become clear to my understanding.
There is a way to access a certain space of the "nodes" without the use of the foreach
?