我正在尝试使用以下代码 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;
?>
以这种方式的代码有效。
但是,如果不是“ https://www.betfair.com/exchange/football ”,而是选择“ https://www.betfair.com/exchange/football/event?id=28040884 ”,则代码将停止工作。
请帮忙。