首页 \ 问答 \ PHP curl下载cookie和javascript保护文件(PHP curl downloading cookie & javascript protected file)

PHP curl下载cookie和javascript保护文件(PHP curl downloading cookie & javascript protected file)

我想从以下链接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上,以便将文件保存在服务器上,我可以进行其余的处理


I am trying to download the file from the following link Desired File

When I download it manually it has a closing.lis file as desired. But when I use following curl code it returns a file with 924bytes. If I try to extract it on computer it says file is damaged. But if I click edit in my cuteFTP program it returns following output

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();This site requires JavaScript and Cookies to be enabled. Please change your browser settings or upgrade your browser.

My curl code is as follows

$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);

Later I also tried getting to cookie and run the code but no success. The cookie file when saved has no data.

 $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);

I need to put the above download on cronjob so that it saves the file on the server and I can do rest of the processing


原文:https://stackoverflow.com/questions/18204640
更新时间:2023-09-13 07:09

最满意答案

是的,你可以做到这一点,或多或少忘记所有花哨的PHP集成内容 (这就是为你提供通用-PHP-Interpreter-As-FastCGI)并将你的应用程序编写为FastCGI服务器本身。

这是一个完整的“主题”,但您可能想要了解Perl应用程序如何为其提供指导。


Yeah, you can do that, by more or less forgetting about all of the fancy PHP integration stuff (that being what's giving you General-Purpose-PHP-Interpreter-As-FastCGI) and writing your application as a FastCGI server in and of itself.

That's kind of a whole 'nother topic, but you might want to look into how Perl apps go about it for a guide.

相关问答

更多
  • 正如@ user3584460所要求的那样,我决定改变我所有的路由以传递所需的控制器/动作作为查询字符串参数。 这里是如何完成的。 我改变了所有的路线来传递一个_url参数: RewriteRule "^noticias/?$" index.php?_url=/noticias/frontend/list/ [L,QSA] 这样我就不会得到错误“没有指定输入文件”,但框架(zend)不会识别路线,并且会始终显示主页。 路由调度程序希望$requestUri变量的格式为index.php/module/co ...
  • mysql可能正试图在Web服务器的连接上执行反向DNS。 如果您不需要按DNS名称过滤mysql连接,请将skip-name-resolve添加到您的mysql配置文件中 I have no idea why, but the solution to this was to install PHP 5.3. I had PHP 5.2.10 running, and I guess 5.3 added some extensive optimizations for Windows. Or fixed s ...
  • 我通过在我的NAS上直接安装FFP 0.7来解决这个问题。 :) I fixed this by installing FFP 0.7 on my NAS direcly. :)
  • 我有三个使用FastCGI的廉价托管计划的客户端,并且由于FastCGI本身而没有遇到任何问题。 这些都是Mongrel不需要的低流量站点。 rails + fast.cgi会为用户提供一个很好的体验 这完全取决于你想要做什么。 如果你打算建立一个用户上传和播放视频的网站,那么FastCGI不是一个好选择。 或者我应该在这种情况下选择php + my-favorite-framework作为平台 你总是为这份工作选择正确的工具。 没有任何关于你想要构建的细节,我不确定这里有人能告诉你如何构建它。 I hav ...
  • 如果您提示代码 , 在严格模式下运行 ,并且不使用这样的全局变量,那么您不会犯这样的错误。 同样在nodejs Web应用程序中,您通常希望使服务器无状态并将所有数据保留在数据库中。 这也将使其成为一个更具可扩展性的架构。 在安全性非常重要的应用程序中,您可以对其进行大量模糊测试以发现类似的问题。 如果您完成所有这些工作,加上严格的代码审查流程,您根本不必担心。 基本上使用fastCGI,即使它的名字fast ,将它与使用节点的http服务器进行比较,它也会非常慢。 在fastCGI解决方案下,我们可以处理 ...
  • 啊,我们有十几次这样的问题。 解决方案是让我们将php和nginx放在同一个用户组下。 Short tags were the problem.
  • 为了将来参考,您可以使用http://php.iis.net/轻松地将php安装到您的IIS设置中。 它带有一个管理器,它也会让你进入'开发模式',它将显示php错误而不是覆盖它们。 For future reference you can use http://php.iis.net/ to easily install php into your IIS setup. It comes with a manager which will also let you go into 'development ...
  • 查看我的Web服务器,无论有多少Apache实例运行,我每次只运行一个FastCGI进程。 所以我不得不假设它正在排队。 Looking at my web server, I only have one of each FastCGI process running at any one time, no matter how many Apache instances are running. So I have to assume it's queuing them up.
  • 此外,尝试先删除Nette缓存。 I've finally found a solution. It is probably Nette / Cassandra related problem. The error was appearing because of object Nette\Security\Identity, after I assigned user data into it: public function authenticate(array $credentials) { / ...
  • 是的,你可以做到这一点,或多或少忘记所有花哨的PHP集成内容 (这就是为你提供通用-PHP-Interpreter-As-FastCGI)并将你的应用程序编写为FastCGI服务器本身。 这是一个完整的“主题”,但您可能想要了解Perl应用程序如何为其提供指导。 Yeah, you can do that, by more or less forgetting about all of the fancy PHP integration stuff (that being what's giving you ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。