PHP cURL不被允许?

时间:2016-12-28 20:35:40

标签: php redirect curl same-origin-policy

我试图使用cURL抓取一个页面,但我的所有尝试都无法正常工作。

这是我的代码:

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;
}

我通过运行获得的响应如下:

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

我不知道该怎么做,因为我不明白问题所在。任何人都可以帮助我吗?

0 个答案:

没有答案