我正在尝试从以下链接下载该文件 Desired File
当我手动下载它时,它根据需要有一个closing.lis文件。但是,当我使用以下curl代码时,它返回一个924bytes的文件。如果我尝试在计算机上提取它,它说文件已损坏。但是如果我在cuteFTP程序中单击编辑它会返回以下输出
function setCookie(c_name,value,expiredays){var exdate = new Date(); exdate.setDate(exdate.getDate()+ expiredays); document.cookie = c_name +“=”+ escape(value)+((expiredays == null)?“”:“; expires =”+ exdate.toGMTString())+“; path = /”; function getHostUri(){var loc = document.location; return loc.toString(); } setCookie('YPF8827340282Jdskjhfiw_928937459182JAX666','69 .167.137.119',10); setCookie('DOAReferrer',document.referrer,10); location.href = getHostUri();此网站需要启用JavaScript和Cookie。请更改您的浏览器设置或升级您的浏览器。
我的卷曲代码如下
$url = "http://www.kse.com.pk/scripts/communicator.php?f=20130812.lis.Z&l=Hd";
$path = "data1/20130812.lis.Z";
$fp = fopen($path, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
后来我也尝试过使用cookie并运行代码但没有成功。保存时的cookie文件没有数据。
$path = "data1/20130812.lis.Z";
$fp = fopen($path, 'w');
$ckfile = tempnam ("./", "CURLCOOKIE");
$ch = curl_init ("http://www.kse.com.pk/scripts/communicator.php?f=20130812.lis.Z&l=Hd");
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
$ch = curl_init("http://www.kse.com.pk/scripts/communicator.php?f=20130812.lis.Z");
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
$output = curl_exec($ch);
curl_close($ch);
我需要将上面的下载放在cronjob上,以便将文件保存在服务器上,我可以进行其余的处理
答案 0 :(得分:3)
好的,所以这段代码才有效:
$str = file_get_contents($url);
list($x, $y, $z) = explode("setCookie(", $str);
list($y) = explode(")", $y);
list($z) = explode(")", $z);
list($a[0], $a[1]) = explode(', ', $y);
list($a[2], $a[3]) = explode(', ', $z);
foreach ($a as &$b) {
$b = trim ($b, "'");
}
$cookie_str = "$a[0]=$a[1]; $a[2]=$a[3]";
$path = "data1/20130812.lis.Z";
$fp = fopen($path, 'w');
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_COOKIE, $cookie_str);
curl_setopt ($ch, CURLOPT_FILE, $fp);
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_exec($ch);
curl_close($ch);
fclose($fp);
给我赏金! :d
答案 1 :(得分:1)
您只需使用file_get_contents('http://www.kse.com.pk/scripts/communicator.php?f=20130812.lis.Z&l=Hd')
抓取文件,并将其写在磁盘上。
但似乎你的文件通过了一个需要启用JS的脚本。