PHP cURL not being allowed?

220 views Asked by At

I'm trying to scrape a page with the use of cURL but all of my attempts doesn't work.

Here's my code:

PHP

public function curl($url) {
    $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $data = curl_exec($ch);

    $loc = null;
    if(preg_match('#Location: (.*)#', $data, $r)) {
        $loc = trim($r[1]);
    }

    echo "<pre>";
    echo var_dump($data);
    echo "</pre>";
    echo "<pre>";
    echo var_dump($loc);
    echo "</pre>";
    die();

    return $data;
}

The response I get by running that is the following:

HTTP/1.1 503 Service Temporarily Unavailable
Date: Wed, 28 Dec 2016 20:29:28 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Set-Cookie: __cfduid=d6f3effa0b8c33cd8092e9f003d5c751c1482956968; expires=Thu, 28-Dec-17 20:29:28 GMT; path=/; domain=.thedomaintoscrape.com; HttpOnly
X-Frame-Options: SAMEORIGIN
Refresh: 8;URL=/cdn-cgi/l/chk_jschl?pass=1482956972.162-3LFzqX3Gdh
Cache-Control: no-cache
Server: cloudflare-nginx
CF-RAY: 3187c3bb054a551c-ORD

I don't really know what to make of it as I don't understand what the problem is. Can anyone help me?

0

There are 0 answers