I'm trying to make an application to grab certain values from a page and insert them into a page of mine. I do not know how to program, but I'm still risking it, because it's to improve my job (bid analyst).
So far I have managed to get one of the data, but the other two I can not get.
I'm using CURL
to get session data, and Dom
to get the values I need. Here's my code so far:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
// iniciar sessao
$ch = curl_init();
// opcoes
curl_setopt($ch, CURLOPT_URL, "https://www.comprasnet.gov.br/pregao/fornec/Acompanhar.asp");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIE, ');
//executar sessao
$output = curl_exec($ch);
if ($output === FALSE) { // verifica erros no curl
echo "cURL Error: " . curl_error($ch);
}
//fechar sessao
curl_close($ch);
$dom = new DOMDocument;
$dom->loadHTML($output);
// Consultando atributo onclick
$codsprg = $dom->getElementsByTagName('a');
foreach ($codsprg as $codprg) {
$onclick[] = $codprg->getAttribute('onclick');
}
$origens = array('Motivo_Suspensao(', ');', 'Dados_Pregao(');
$destinos = array('', '', '');
$nova = str_replace($origens, $destinos, $onclick);
$nova = array_filter($nova);
$nova = array_unique($nova);
$nova = array_slice($nova, 0);
// resultado
echo '<pre>';
//print_r ($nova); Até aqui funciona
$numsprg = $dom->getElementsByTagName('a');
foreach ($numsprg as $numprg) {
$num[] = $numprg->getAttribute('onclick');
}
$new = $num;
echo $new;
?>
Code that I want to get: I need to get the data of the trading floor, which is in parentheses (I already have), the trading floor number that is on the same line as the trading floor data (ex: 512016) and uasg
is on the bottom line (ex: 155023).
In the first part of the code I make the connection to CURL
, then I use DOM
to get the first one I need (data_prepare). After that I have tested several possible combinations with the DOM and always return errors like:
Trying to get property of non-object e Call to undefined method DOMDocument::find() in
I have already researched here in SOpt and tested all possible solutions, without success. The current error is:
Notice: Array to string conversion in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\aclicita\teste.php on line 49
Line 49 is:
echo $new;