Hola soy bien novato programando tengo un código para capturar paginas. Me funciona con la mayoría de paginas pero por ejemplo cuando lo intento con http://www.filemare.com/
me redirige a la pagina http://www.filemare.com
/ y no a mi index
Este es el codigo:
$curl = curl_init();
$header[0] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: es-419,es;q=0.8";
$header[] = "Pragma: ";
curl_setopt($curl, CURLOPT_URL, "http://www.filemare.com/");
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_REFERER, "https://www.google.cl/");
curl_setopt($curl, CURLOPT_ENCODING, "gzip,deflate");
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$html = curl_exec($curl);
echo 'Curl error: ' . curl_error($curl);
curl_close($curl);
echo $html;
Si me pudieran ayudar a encontrar mi problema de los agradecería mucho ;D
Saluds
MOD: Etiquetas GeSHi obligatorias. Normas del subforo de PHP (http://foro.elhacker.net/php/obligatorio_normas_del_subforo_de_php_18072014-t148495.0.html)
No creo entender bien el problema, ¿No quieres que te redirija?
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
¿El curl se ejecuta bien?
Exacto, intente lo que me sugeriste pero igualmente me redirige :-(
Mi idea es capturar para después aplicarle expresiones regulares
Es raro, el curl me devuelve el error 301:
m1n054@debiantest:~$ curl -iv 'http://www.filemare.com'
* Rebuilt URL to: http://www.filemare.com/
* Hostname was NOT found in DNS cache
* Trying 198.7.57.228...
* Connected to www.filemare.com (198.7.57.228) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: www.filemare.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
HTTP/1.1 301 Moved Permanently
* Server nginx is not blacklisted
< Server: nginx
Server: nginx
< Date: Thu, 31 Jul 2014 15:11:40 GMT
Date: Thu, 31 Jul 2014 15:11:40 GMT
< Content-Type: text/html
Content-Type: text/html
< Content-Length: 178
Content-Length: 178
< Connection: keep-alive
Connection: keep-alive
< Location: http://filemare.com/
Location: http://filemare.com/
<
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
Prueba a agregar:
curl_setopt($curl, CURLOPT_MAXREDIRS, 0);
Y si esto no funciona, prueba a eliminar por completo las dos entradas, debería tomar el valor por default de no seguir los locations.
Citary no a mi index
¿ Como que y no a tu index ? Tienes usuario o algo asi ?
Saludos
Tampoco me resulto.
Mirando el codigo fuente de la pagina detecte que este un javascript era el culpable
<script type="text/javascript">
eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('2(5!=1)1.0=0;2(0.6!=\'3.4\')1.0=\'7://3.4\';',8,8,'location|top|if|filemare|com|self|hostname|http'.split('|'),0,{}))
</script>
<script type="text/javascript">
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('8 F(j){3 5=j.b.v(\'/\');6(5[0]==\'\')5.L();6(5[5.C-1]==\'\')5.17();7 5}8 M(5){7(\'/\'+5.B(\'/\'))}8 N(h){7 h&&h.A(/^[a-z]{2}(-[a-z]{2})?$/i)}8 E(j){3 r={};6(j.9!=\'\'){3 u=j.9.Z(1).v(\'&\');m(3 i=0;i<u.C;i++){3 k=u[i].v("=");r[x(k[0])]=k[1]?x(k[1]):I}}7 r}8 H(4,c){c=c.o();m(3 a w 4){6(c==a.o()){7 U}}7 V}8 K(4){3 q={};m(3 a w 4){6(!a.A(/^[0-R-z]{O}$/i))q[a]=4[a]}7 q}8 J(4){3 p=[];m(3 a w 4){p.14(y(a)+(4[a]?(\'=\'+y(4[a])):\'\'))}3 h=p.B(\'&\');6(h==\'\')7\'\';7\'?\'+h}8 10(){3 l={"b":e.g.b,"9":e.g.9,"t":e.g.t};3 f=n.11(\'D\');6(f){3 d=f.X||f.12.n;6(d){3 s=13.16(d.W.P);n.D=s;6(s.G){3 5=F(l);6(N(5[0]))5.L();5.Y(s.G.o());l.b=M(5)}3 4=E(l);6(s.c){6(!H(4,s.c)){4[s.c]=I}}Q{4=K(4)}l.9=J(4);6(l.b!=e.g.b||l.9!=e.g.9){e.S(8(){e.g.T(l.b+l.9+l.t)},15)}}}}',62,70,'|||var|args|path|if|return|function|search||pathname|xid||window||location|str||loc|item||for|document|toLowerCase|pairs|args2|result||hash|data|split|in|decodeURIComponent|encodeURIComponent||match|join|length|state|parse_args|parse_path|locale|args_have_xid|null|fmt_args|args_remove_xid|shift|fmt_path|is_locale|40|textContent|else|9a|setTimeout|replace|true|false|body|contentDocument|unshift|substr|on_state|getElementById|contentWindow|JSON|push|500|parse|pop'.split('|'),0,{})) </script>
Bueno al final opte por rescatar la información mediante un archivo y trabajar con el.
Dejo si alguien le sirve
$ch = curl_init("http://www.filemare.com/");
$fp = fopen("filemare.html", "w");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es,en"));
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Disculpen las molestias y gracias por todo
cUrl no interpreta javascript -___-
Edit: Ya vi el echo... perdon xD
Saludos
Cita de: #!drvy en 31 Julio 2014, 22:09 PM
cUrl no interpreta javascript -___-
Saludos
Pero si imprimes la variable $HTML como lo está haciendo el, en la última linea, si imprime el javascript en el navegador lo que hace parecer que esta redirigiendo.
Aún así, probe tu código tal cual solo con el false en followlocation y me regreso el 301 de Nginx y ningún archivo javascript.
Quizás lo que estaba pasando era que el 301 te enviaba a otra página y está te enviaba a otra página. Un doble redirect por así decir. Claro que el $HTML solo debería regresar el codigo 301 de Nginx si deshabilitas el followlocation.
Si quieres imprimir el codigo para observarlo puedes simplemente cambiar:
echo $html;
por
echo htmlentities($html);
En mi web, estoy escribiendo artículos relacionados con éste tema. Por si te interesa, en un par de días habrá uno nuevo para hacer nuestra propia API de Twitter con PHP
http://zonaisc.webcindario.com/?p=35