Curl - Mega Sena result by contest number

0

script by Daniel Omine modified by me. Original: link

 $c = curl_init();
$cookie_file = __DIR__.DIRECTORY_SEPARATOR.'megasena.txt';
curl_setopt_array($c, array(
    CURLOPT_URL => 'http://www.loterias.caixa.gov.br/wps/portal/loterias/landing/megasena',
    CURLOPT_REFERER => 'http://www.loterias.caixa.gov.br',
    CURLOPT_USERAGENT => 'Foo Spider',
    CURLOPT_HEADER => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CONNECTTIMEOUT => 6,
    CURLOPT_TIMEOUT => 6,
    CURLOPT_MAXREDIRS => 1,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_COOKIESESSION => true,
    CURLOPT_COOKIEFILE => $cookie_file,
    CURLOPT_COOKIEJAR => $cookie_file
    ));

try {
    $content = curl_exec($c);
    $data = curl_getinfo($c);
    $data['content'] = $content;
    unset($content);
    $data['errno'] = curl_errno($c);
    $data['errmsg'] = curl_error($c);
    if ((int)$data['errno'] !== 0 || (int)$data['http_code'] !== 200) {
        echo 'error number: '.$data['errno'];
        echo 'error message: '.$data['errmsg'];
        echo 'http status: '.$data['http_code'];
    //print_r($data);
        exit;
    }
} catch (HttpException $ex) {
    print_r($ex); exit;
}

curl_close($c); 

$doc = new DOMDocument();
$doc->loadHTML($data['content']);
unset($data);
$tags = $doc->getElementsByTagName('div');
$dezenas = $doc->getElementsByTagName('ul');
$proximo = $doc->getElementsByTagName('div');

$data = null;

foreach ($tags as $tag) {
    if ($tag->getAttribute('class') == 'title-bar clearfix') {
        $data = trim($tag->textContent);
        break;
    }
}

foreach ($dezenas as $dez) {
    if ($dez->getAttribute('class') == 'numbers mega-sena') {
        $dataDezenas = trim($dez->textContent);
        break;
    }
}
foreach ($proximo as $prx) {
    if ($prx->getAttribute('class') == 'next-prize clearfix') {
        $proximoPremio = trim($prx->textContent);
        break;
    }
}

$dezenas = str_split($dataDezenas,2);
print 'concuros nº: '.substr($data,42,4)." data:".substr($data,48,10) ;
print '<br />'.substr($proximoPremio,0,54).' '.substr($proximoPremio, 63,16);


print'<pre>';
print_r($dezenas);
print'</pre>';

Code running 100% follow return

concuros nº: 1878 data:19/11/2016
Estimativa de prêmio do próximo concurso 23/11/2016 R$ 13.400.000,00

Array
(
    [0] => 12
    [1] => 16
    [2] => 26
    [3] => 40
    [4] => 56
    [5] => 57
)

I saw that on the site link has a field to do the search by get the url get does not follow a pattern, I think it is encrypted.

Example of the url with the search.

Search for: 1877 url: link

Search for: 1876 url: link

Can you make this query by contest through the url?

It seems that even informing the modified url it brings the most recent result.

    
asked by anonymous 23.11.2016 / 15:58

0 answers