2
我想刮538棒球賠率網站。CURL返回垃圾
當我將URL粘貼到Chrome並查看源代碼時,它看起來像標準HTML。
當我湊的數據(我用下面兩個密碼和file_get_contents
具有相同的結果),我得到的東西看起來像: } KS8> j [ ߔ8
我試過了簡單網站上的代碼,沒有問題。該網站以某種方式阻止我的獲得?
<?php
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
}
$output = curl('https://projects.fivethirtyeight.com/2017-mlb-predictions/games/');
echo $output;
?>
使用本也捲曲'curl_setopt($ CH,CURLOPT_ENCODING, '身份');' – Gaurav