I'm trying to download content from a website, but it's giving this warning:
'DOMDocument :: loadHTML (): Unexpected end tag: tr in Entity
And it is indicating several lines. I can not fix the accent either.
Could anyone help me understand and solve these problems?
$content = http_build_query([
'Local' => 'Adamantina',
'Inicio' => '01/01/2015',
'Final' => '31/12/2015',
]);
$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $content,
]
]);
$contents = utf8_decode(file_get_contents('http://www.ciiagro.sp.gov.br/ciiagroonline/Listagens/BH/LBalancoHidricoLocal.asp', false, $context));
$dom = new DOMDocument();
$dom->loadHTML($contents);
$dom->saveHTML($dom->documentElement);
$xpath = new DomXPath($dom);
$rows = $xpath->query('//table/tr[position()>0]');
foreach ($rows as $row) {
$tds=$row->getElementsByTagName("td");
foreach ($tds as $td) {
print($td->nodeValue);
echo "<br>";
}
}