1
I’m trying to make an application to take certain values from a page and insert them into a page of mine. I don’t know how to program, but I’m still taking a risk, because it’s to improve my function (bidding analyst).
So far I’ve managed to get one of the data, but the other two I’m not getting.
I’m using CURL
to retrieve session data, and Dom
to get the values I need. Follow 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 I want to pick up: I need to get the data of the trading floor, which is between parentheses (I already got), the number of the trading floor that is in the same row of the trading floor data(ex: 512016) and the uasg
that is on the line below(ex: 155023).
In the first part of the code I connect to the CURL
, then use the DOM
to get the first data I need (data). I have tried several possible combinations with the DOM and always return errors such as:
Trying to get property of non-object e Call to undefined method DOMDocument::find() in
I have already researched here at 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
The line 49 is:
echo $new;
It would be better to say more specifically which errors and which lines. About "I don’t know how to program, but I’m still taking a risk", it’s not a problem, because most of the things with PHP here fit perfectly in this profile (even if the author "swears he’s a programmer"). If you can [Dit] the issue and split your problem into smaller problems, or detail the bugs, it helps. A good question regardless of your current ability to program. Here are some tips: [Ask], [Help].
– Bacco
@Inkeliz, the data I need are in the attached image. Dados_pregao(XXXXXX) = I need to get the numbers between parentheses (So far I got. On the same line has the return that is 512016 (this data I need). And on the line just below has 155023 (this is the other data I need). The rest I don’t need.
– John Pablo Martins
@Bacco, I’ll report the error as is the code now.
– John Pablo Martins
So that the clasps in a?
– Bacco
I put for a better view with print_r, to number the output so I can use later, like: [0], [1], ... If I’m wrong correct me, please.
– John Pablo Martins
in this case do not use echo to show, use print_r
– Bacco
My fault, thank you. But let’s see, follow the image with this code I can get the data.
– John Pablo Martins
Good evening, I manually downloaded the CURL "https://www.comprasnet.gov.br/pregao/provid/Acompanhar.asp" URL and show a denied access message redirecting to https://www.comprasnet.gov.br/accessdenied.htm
– Fernando Mertins
This page is only accessible after logging in to the browser.
– John Pablo Martins
Still using Curl, first you need to log in!
– Ed Cesar