0

我需要 POST cookies.txt 然后使用 CURL 将页面下载到文本文件。这是我的 FGC 示例,但显然 FGC 不擅长 cookie,所以我需要 CURL。

<?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 会很棒另外,如果你有另一种更快的方法,请发布!

4

1 回答 1

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);
于 2013-05-20T19:53:39.220 回答