Cur post proted

  • Autor Autor xaiborweb
  • Fecha de inicio Fecha de inicio

xaiborweb

Programador
No recomendado
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
hoal compañeros estoy intentando hacer curl a esta pagina
HTML:
https://www.rexpelis.com/
las paginas 2,3,4, etc... las trae por medio de método post con un token esto es lo que llevo pero no funciona
PHP:
function curl($url,$referer,$metodopost,$cookies){
    $ch = curl_init($url);
    $headers = array(
        'accept-language: en-US;q=0.6,en;q=0.4',
        'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'
    );
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    if(!empty($referer)){
        curl_setopt($ch, CURLOPT_REFERER, $referer);
    }else{
        curl_setopt($ch, CURLOPT_REFERER, $url);
    }
    if(!empty($metodopost)){ 
        curl_setopt($ch, CURLOPT_POST, TRUE); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, $metodopost); 
    }
    if(!empty($cookies)){
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
    }
    $source = curl_exec($ch);
    curl_close($ch); 

    if(!empty($source)){ 
        return $source;
    }
}

$url = 'https://www.rexpelis.com/';
$cookie = 'C:\xampp\htdocs\bot\es\faltantes\rexpelis.txt';
echo $html = curl($url,'','',$cookie);

preg_match_all('|name="csrf-token" content="(.*)"|sU', $html, $toke);
$token = $toke[1][0];
//curl
$pague = $url.'pagination';
$metodopost = array('page'=>'2','type'=>'movie','_token'=>$token);
echo $html = curl($pague,$url,$metodopost,$cookie);
alguien puede ver donde esta el error? o que me falta? gracias 😉
 
Arregla la funcion curl. dado que este hecha una mrd.

despues de arreglarla, recuerda guardar y conservar la cookie correctamente.

segundo usa curl con opts no la forma 'progresiva' que andas intentando usar.
PHP + curl, HTTP POST sample code? - Stack Overflow

$post = [
'page' => 2,
'type' => 'movie',
'_token' => $token,
];

curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
Envialos en JC no en array asociativo.
 
hola amigo gracias por responder.

no entiendo que esta mal en la función curl ? la llevo trabajando bien mucho tiempo con otras paginas podrías compartir un ejemplo funcional si fueras tan amable?

con la misma función curl y este code me entrega una pagina en blanco
PHP:
$url = 'https://www.rexpelis.com/';
$cookie = 'C:\xampp\htdocs\bot\es\faltantes\rexpelis.txt';
$html = curl($url,'','',$cookie);

preg_match_all('|name="csrf-token" content="(.*)"|sU', $html, $toke);
$token = $toke[1][0];
//curl season
$pague = $url.'pagination';
$metodopost = [
'page' => 2,
'type' => 'movie',
'_token' => $token,
];
echo $html_pague = curl($pague,$url,$metodopost,$cookie);
cuando debería entregarme un html como este
HTML:
<div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/han-llegado-1996">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/lheveh25avCj0Mq8xGMQ.jpg" data-src="" alt=""><span class="year text-center">1996</span></figure>
            </div>
            <div class="item-detail"><p>Han llegado (1996)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/antes-y-despues-1996">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/h30GgMzcOniO9tqvvm6z.jpg" data-src="" alt=""><span class="year text-center">1996</span></figure>
            </div>
            <div class="item-detail"><p>Antes y después (1996)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/los-colegas-del-barrio-1996">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/2Rery8Cw7VskYn2iRIpM.jpg" data-src="" alt=""><span class="year text-center">1996</span></figure>
            </div>
            <div class="item-detail"><p>Los colegas del barrio (1996)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/corazon-de-dragon-1996">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/IQW8ErsbMnAsMOZILS2C.jpg" data-src="" alt=""><span class="year text-center">1996</span></figure>
            </div>
            <div class="item-detail"><p>Corazón de dragón (1996)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/pasion-obsesiva-1996">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/6N9DwX6RdSoQDZw6Xo6e.jpg" data-src="" alt=""><span class="year text-center">1996</span></figure>
            </div>
            <div class="item-detail"><p>Pasión obsesiva (1996)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/volando-libre-1996">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/8SPpp8fTlkrDvag9qn5a.jpg" data-src="" alt=""><span class="year text-center">1996</span></figure>
            </div>
            <div class="item-detail"><p>Volando libre (1996)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/jerry-maguire-1996">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/VEZGExjxxDLWOoObPQ4T.jpg" data-src="" alt=""><span class="year text-center">1996</span></figure>
            </div>
            <div class="item-detail"><p>Jerry Maguire (1996)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/las-manias-de-mama-1996">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/uWPUvhRxEjJ6aEUT1aFI.jpg" data-src="" alt=""><span class="year text-center">1996</span></figure>
            </div>
            <div class="item-detail"><p>Las manías de mamá (1996)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/el-secreto-de-mary-reilly-1996">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/uwM3TLFBS4XdKR8w7OYl.jpg" data-src="" alt=""><span class="year text-center">1996</span></figure>
            </div>
            <div class="item-detail"><p>El secreto de Mary Reilly (1996)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/the-quest-en-busca-de-la-ciudad-perdida-1996">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/7aSzyVc9OHRwupBNne0m.jpg" data-src="" alt=""><span class="year text-center">1996</span></figure>
            </div>
            <div class="item-detail"><p>The Quest: En busca de la ciudad perdida (1996)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/en-tierra-peligrosa-2-1997">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/February2019/WJMgHIpPnLYPc03jCWVn.jpg" data-src="" alt=""><span class="year text-center">1997</span></figure>
            </div>
            <div class="item-detail"><p>En tierra peligrosa 2 (1997)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/triple-9-2016">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/December2018/ITFtl5ZKj05XRa0zmkmS.jpg" data-src="" alt=""><span class="year text-center">2016</span></figure>
            </div>
            <div class="item-detail"><p>Triple 9 (2016)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/the-little-stranger-2018">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/December2018/7pYufLecdPbTVFfZ0frw.jpg" data-src="" alt=""><span class="year text-center">2018</span></figure>
            </div>
            <div class="item-detail"><p>The Little Stranger (2018)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/un-pequeno-favor-2018">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/December2018/zVfMCQnuf68LABgycEdO.jpg" data-src="" alt=""><span class="year text-center">2018</span></figure>
            </div>
            <div class="item-detail"><p>Un pequeño favor (2018)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/acusada-2018">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/December2018/AawJvh8jFLxVCW5L8TF3.jpg" data-src="" alt=""><span class="year text-center">2018</span></figure>
            </div>
            <div class="item-detail"><p>Acusada (2018)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/los-dioses-deben-estar-locos-2-1989">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/December2018/sqTrAGhwrw9bd2EFrwzd.jpg" data-src="" alt=""><span class="year text-center">1989</span></figure>
            </div>
            <div class="item-detail"><p>Los dioses deben estar locos 2 (1989)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/amityville-1979">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/December2018/mAnlcrbWt0H3Fl8c94Jx.jpg" data-src="" alt=""><span class="year text-center">1979</span></figure>
            </div>
            <div class="item-detail"><p>Amityville (1979)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/amityville-ii-la-posesion-1982">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/December2018/mwmfcTLj36f09SAcZeyC.jpg" data-src="" alt=""><span class="year text-center">1982</span></figure>
            </div>
            <div class="item-detail"><p>Amityville II: La posesión (1982)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/amityville-iii-el-pozo-del-infierno-1983">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/December2018/egxDrG7TEMpeFcyJoLFx.jpg" data-src="" alt=""><span class="year text-center">1983</span></figure>
            </div>
            <div class="item-detail"><p>Amityville III: El Pozo del Infierno (1983)</p></div>
        </a>
    </div>
    <div class="item-pelicula pull-left">
        <a href="https://www.rexpelis.com/pelicula/el-maestro-borracho-1978">
            <div class="item-picture">
            <figure><img class="lazyload" src="https://rexpelis.com/storage/movies/December2018/N5hkFdTKcduKzhBh1psV.jpg" data-src="" alt=""><span class="year text-center">1978</span></figure>
            </div>
            <div class="item-detail"><p>El maestro borracho (1978)</p></div>
        </a>
    </div>
 
Última edición:

Que sitio más raro wtf, ya he intentado de varias formas no le encuentro el truco xD el post pagination siempre me devuelve vació y envió correctamente el cuerpo... ya mire con charles proxy y me devuelve el html encriptado jajaj muy interesante como envitan los bots robadores de contenido... En php me devolvió el 419 y buscando en google encontré php - Ajax LARAVEL 419 POST error - Stack Overflow supuestamente falta enviar ese token pero se envía la verdad no se donde esta el truco xD
 
https://forobeta.com/php/694418-clase-navegar-webs-curl-php.html

PHP:
<?php
require_once('cURL.php');

$cURL = new cURL('cookies3.txt', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36');

$URL = 'https://www.rexpelis.com';
$cURL->browse($URL, $URL);

preg_match('/name="csrf-token" content="([a-z0-9]+)"/i', $cURL->result, $token);

$postFields = 'page=2&type=movie&_token='.$token[1];
$cURL->headers = array(
	'content-length: '.strlen($postFields),
	'x-requested-with: XMLHttpRequest',
);

echo $cURL->browse($URL.'/pagination', $URL, $postFields)->result;

?>

:sorprendidos:
 
Última edición:

jajaj me había comido una cabecera con razón el error WTF...Gracias por contestar la duda quedo aclarada 😉

Dejo mi versión no es tan elegante y bien hecha como la tuya brother pero bueno todos tenemos derecho a publicar 😉

PHP:
<?php
function curl($url, $post_data="", $headers="", $cookie_file=""){
    $curl = curl_init($url);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);

    if(!empty($headers)){curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);}

    if(!empty($post_data)){
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
    }

    if(!empty($cookie_file)){
        curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
        curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file);
    }

    $response = curl_exec($curl);

    if(curl_error($curl)){
        $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $error = "Error = " . curl_error($curl) . " - " . 'HTTP code: ' . $httpcode;
        curl_close($curl);
        return array(false, $error);
    }

    curl_close($curl);

    return (empty($response) ? array(false, "No hay nada de respuesta.") : array(true, $response));
}

$url = "https://www.rexpelis.com";
$cookies = "C:\UniServerZ\www\curls_testings\cks.txt";
$headers = array();
$headers[]='User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31';

$uno = curl($url,"",$headers,$cookies);
if($uno[0] === true){
    preg_match('/<meta name="csrf-token" content="(?<token>.*?)">/', $uno[1], $token);

    $post_data = 'page=2&type=movie&_token='.$token['token'];

    $headers[]='content-length: ' . strlen($post_data);
    $headers[]='x-requested-with: XMLHttpRequest';

    $dos = curl($url . "/pagination",$post_data,$headers,$cookies);

    if($dos[0] === true){
        echo $dos[1];
    }else{
        echo "error [2] = " . $dos[1];
    }
}else{
    echo "error [1] = " . $uno[1];
}
?>