中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

php 抓取圖片

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線(xiàn)!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
php 獲取網(wǎng)站圖片并存入本地文件
<?php
/**
 * Created by PhpStorm.
 * Date: 15-2-9
 * Time: 下午3:10
 */
 
for($i=0;$i<1000;$i++){
    $getData['page'] =  $i+1;
    getImg($getData);
}
 
 
function getImg($getData)
{
    $path = "D:/NFS/img/";
    $opts = array(
        'http'=>array(
            'method'=>"GET",
            'timeout'=>3,//設(shè)置3秒等待
        ),
    );
    if(is_array($getData) && !empty($getData))
    {
        $ser = http_build_query($getData, '', '&');
    }
    $cnt=0;
   //如果請(qǐng)求失敗 繼續(xù)請(qǐng)求3次
    while($cnt<3 && ($file=file_get_contents("http://sexy.faceks.com/?{$ser}", false, stream_context_create($opts)))===FALSE) $cnt++;
    preg_match_all("/\<img.*?src\=\"(.*?)\"[^>]*>/i", $file, $matches);
    if(empty($matches[0]) || empty($matches[1]))
    {
        echo "not img...";die;
    }
 
    $imgs=array_unique($matches[1]);
    foreach($imgs as $k=>$img)
    {
 
        $filename = $path.time().$k.".jpg";
        getImage($img,$filename);
    }
 
}
 
/**
 * @param string $url
 * @param string $fileName
 * 保存圖片
 */
function getImage($url = '', $fileName = '')
{
    var_dump($fileName);
    $ch = curl_init();
    $fp = fopen($fileName, 'wb');
 
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
 
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
}

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀(guān)點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:php計(jì)算網(wǎng)頁(yè)執(zhí)行時(shí)間

下一篇:使用PHP下載CSS文件中的圖片的代碼