Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在betfair上被阻止了吗?_Php_Curl_Web Scraping_Betfair - Fatal编程技术网

Php 在betfair上被阻止了吗?

Php 在betfair上被阻止了吗?,php,curl,web-scraping,betfair,Php,Curl,Web Scraping,Betfair,我正试图使用以下php代码在betfair.com网站上进行网页抓取: <?php // Defining the basic cURL function function curl($url) { $ch = curl_init(); // Initialising cURL curl_setopt($ch, CURLOPT_URL, $url); // Setting cURL's URL option with the

我正试图使用以下php代码在betfair.com网站上进行网页抓取:

<?php    
    // Defining the basic cURL function
    function curl($url) {
        $ch = curl_init();  // Initialising cURL
        curl_setopt($ch, CURLOPT_URL, $url);    // Setting cURL's URL option with the $url variable passed into the function
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
        $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
        curl_close($ch);    // Closing cURL
        return $data;   // Returning the data from the function
    }    

    $scraped_website = curl("https://www.betfair.com/exchange/football");       
    echo $scraped_website;          
?>  

代码以这种方式工作

但如果不是“选择” 代码停止工作


请提供帮助。

查看标题:

 HTTP/1.1 302 Moved Temporarily
 Location: https://www.betfair.com/exchange/plus/#/football/event/28040884
 Cache-Control: no-cache
 Pragma: no-cache
 Date: Fri, 09 Dec 2016 17:38:52 GMT
 Age: 0
 Transfer-Encoding: chunked
 Connection: keep-alive
 Server: ATS/5.2.1
 Set-Cookie: vid=00956994-084c-444b-ad26-38b1119f4e38; Domain=.betfair.com; Expires=Mon, 01-Dec-2022 09:00:00 GMT; Path=/
 X-Opaque-UUID: 80506a77-12c1-4c89-b4a6-fa499fd23895
实际上,发送一个302移动的临时HTTP重定向,而您的脚本不遵循重定向,这就是它不起作用的原因。修复这个问题(使用CURLOPT_FOLLOWLOCATION),代码就可以正常工作。固定代码:

function curl($url) {
    $ch = curl_init();  // Initialising cURL
    curl_setopt($ch, CURLOPT_URL, $url);    // Setting cURL's URL option with the $url variable passed into the function
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
    curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
    curl_close($ch);    // Closing cURL
    return $data;   // Returning the data from the function
}
var_dump(curl("https://www.betfair.com/exchange/football/event?id=28040884"));

(我还建议使用CURLOPT_ENCODING=>'',这将使curl在受支持的情况下使用压缩传输,HTML压缩非常非常非常好,使用gzip压缩curl通常编译为支持gzip,这使站点下载速度更快,这使curl_exec()返回速度更快)

您遇到了什么错误?当您启动php代码时,我会看到一个空白页,您可以将这些代码添加到函数中,然后尝试curl\u setopt($ch,CURLOPT\u FOLLOWLOCATION,TRUE);curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);你有权限刮取他们的数据吗?这可能违反了他们的服务条款。我在我的网站上测试了你的代码,但仍然不起作用。这可能是托管网站的错?唉。你是在IRC还是在facebook上?给hanshenrik发个短信irc://irc.freenode.net/ 或者在接下来的两个小时内,我可能会帮你解决这个问题