php cUrl заблокирован на Betfair?

Я пытаюсь сделать веб-очистку на сайте betfair.com с этим кодом php:

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

код таким образом работает.

Но если вместоhttps://www.betfair.com/exchange/football» выбирать «https://www.betfair.com/exchange/football/event?id=28040884«код перестает работать.

Помогите, пожалуйста.

-1

Решение

посмотрите на заголовки, которые получает curl:

 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

на самом деле https://www.betfair.com/exchange/football/event?id=28040884 отправьте 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, что делает загрузку сайта намного быстрее, что делает curl_exec () вернуться гораздо быстрее)

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector