我想从this网站
中提取买卖价值如何使用PHP中的file_get_contents()
执行此操作例如
$abc = file_get_content("https://www.unocoin.com/trade?all");
现在我如何每2分钟从中提取买卖价值?
答案 0 :(得分:1)
如果您要从其他网页中提取数据,请使用php curl
示例强>
function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
print curl_download('https://www.unocoin.com/trade?all');
答案 1 :(得分:0)
对于这个特定的站点,数据是json编码的,所以你需要做的就是它似乎没有任何进一步的身份验证要求,因为我可以到达链接并查看数据。
$abc = file_get_content("https://www.unocoin.com/trade?all");
$decoded_abc=json_decode($abc);
$buy=$decoded_abc->buy;
$sell=$decoded_abc->sell;