4

I'm sure this is fairly simple. I'm using the function below to retrieve sites raw html in order to parse it. during my testing, I decided to run my code on stackoverflow.com

Instead of getting the html response the Chrome is printing out the actual site rather then assigning the html to its veritable. What am I missing?

function get_site_html($site_url) 
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
    curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_URL, $site_url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);

    global $base_url; 
    $base_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    $http_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    curl_close ($ch);
    return $response;
}

The site raw html should be assigned to $response, and then return it.

2
  • please use spaces for proper indentation on stack overflow.
    – Femaref
    Jun 16, 2013 at 14:56
  • 1
    What you've posted looks fine. Are you sure it's not a problem elsewhere in your code?
    – Sam Dufel
    Jun 16, 2013 at 14:58

1 Answer 1

8

Your code works. Try echo htmlentities($response); You'll get the raw html for the site you're curling.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.