【发布时间】:2021-08-12 03:51:37
【问题描述】:
我开始研究从网站中提取数据并找到一些文档并在我的本地主机上运行它们,然后我将代码上传到我的服务器,但数据没有来
freebsd12.2 稳定版
包: nginx-1.20.0_1,2 php80-8.0.6
我的网站代码:
<?php
function getir($baslangic, $son, $cekilmek_istenen)
{
@preg_match_all('/' . preg_quote($baslangic, '/') .
'(.*?)'. preg_quote($son, '/').'/i', $cekilmek_istenen, $m);
return @$m[1];
}
//Ankr Coin
$url = "https://coinmarketcap.com/currencies/ankr/";
$icerik = file_get_contents($url);
$AnkrCoin = getir('<div class="priceValue___11gHJ">','</div>',$icerik);
//Eose
$url = "https://coinmarketcap.com/currencies/eos/";
$icerik = file_get_contents($url);
$EosCoin = getir('<div class="priceValue___11gHJ">','</div>',$icerik);
//Atom
$url = "https://coinmarketcap.com/currencies/cosmos/";
$icerik = file_get_contents($url);
$CosmosAtom = getir('<div class="priceValue___11gHJ">','</div>',$icerik);
//Mkr
$url = "https://coinmarketcap.com/currencies/maker/";
$icerik = file_get_contents($url);
$Mkr = getir('<div class="priceValue___11gHJ">','</div>',$icerik);
?>
<html>
<head>
<meta http-equiv="refresh" content="5">
</head>
<body>
<div id="AnkCoin">
<p>
Ankr:<?php echo $AnkrCoin[0]; ?>
</p>
</div>
<div>
<p>
Eos: <?php echo $EosCoin[0]; ?>
</p>
</div>
<div>
<p>
Cosmos Atom: <?php echo $CosmosAtom[0]; ?>
</p>
</div>
<div>
<p>
Mkr: <?php echo $Mkr[0]; ?>
</p>
</div>
</body>
</html>
我可以在类似这个命令的表达式中看到 google
<?php
$homepage = file_get_contents('http://www.google.com/');
echo $homepage;
?>
但是当我更改链接时没有任何反应 例如
<?php
$homepage = file_get_contents('https://coinmarketcap.com/currencies/eos/');
echo $homepage;
?>
我的错误日志是干净的。
【问题讨论】:
-
使用
curl代替file_get_contents(),因为file_get_contents()不遵循重定向/刷新。但是如果您仍然需要使用file_get_contents(),请检查此php.net/manual/en/context.http.php -
@Haridarshan 我也尝试 curl 但没有任何改变
-
我刚刚通过
curl尝试了这个网址https://coinmarketcap.com/currencies/eos/,我得到了回复。那么,您能否分享一下您尝试过的 curl 代码