Cómo obtener el marcado html de google.com usando curl

I'm write the follwoing:

    $ch= curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_URL, 
            "http://google.com/");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    $output= curl_exec($ch);

    curl_close($ch);
if($output==FALSE) return 'No markup';
    return $output;

and html markup for receiving markup of google.com:

<div class="content">
    <pre>
       <?php
            echo htmlentities($output);
        ?>

    </pre>
</div> 

But when I'm running this script pre tag is contain nada. Why? If I replaced google.com to stackoverflow.com then it works fine. How to fix this?

preguntado el 12 de febrero de 14 a las 05:02

I guess that Google blocks the user agent of curl. -

I guess that google redirects you from http a https. -

With your code I get a valid response and a string length of 44,822 -

for debugging curl requests i do 2 things: 1) curl_getinfo for debugging headers 2) curl_setopt($ch, CURLOPT_VERBOSE, true); for extended information about request proccess -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.