2013-05-20 63 views
0

我需要POST cookies.txt然后使用CURL将页面下载到文本文件。这是我的FGC示例,但显然FGC对Cookie不好,所以我需要CURL。通过CURL使用Cookie下载文件使用PHP

<?php 
    $file = file('source\1.txt'); 
    foreach ($file as $link) 
    { 
     $link  = trim($link); 
     $link2  = "http://site-that.com/authenticates?={$link}"; 
     $downloaded = file_get_contents($link2); 
     $myFile  = "parsed/$link" . ".txt"; 
     $fh = fopen($myFile, 'a') or die('Cannot open file'); 
     fwrite($fh, $downloaded); 
    } 
    $timestamp = time(); 
    rename('source\1.txt', "source/done/done-{$timestamp}.txt"); 
    echo 'Finished'; 

任何想法?代码示例将不胜感激。一个简单的例子,这样做喜欢google.com会很好另外,如果你有另一种方式做到这一点,速度更快,请发表!

+0

FGC对饼干并不坏。此外,您可能希望使用搜索而不是询问问题,但不清楚您在此处运行的问题。显示如何执行的代码包含file_get_contents或curl的Cookie均存在。 – hakre

回答

5
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookieFileName); //$cookieFilename must be a path to a file with cookie data 
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookieFileName); 
//curl_setopt($curl, CURLOPT_COOKIE, $cookie); //you may also use this, here $cookie is a cookie string 
curl_close($curl); 
$data = curl_exec($curl); 
+0

还没有时间检查它,但他们关闭了这个问题,你是唯一的答案,为你的努力,你得到的分=)我会试试看,谢谢! – SuperMar1o