欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

批量下载 妹子图自拍

程序员文章站 2022-05-30 16:16:51
...

源网站图片有重复,下载后请自行去重== 无 ?phpdefine('DocumentRoot', dirname(__FILE__));function curl_file_get_contents($durl, $timeout = 5, $refer = 'http://www.baidu.com') { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $durl); curl_seto

源网站图片有重复,下载后请自行去重 = =
window.setTimeout("window.location=\'' . $url . '\'", ' . $time . ');';
    exit();
}

function _mkdir($dir) {
    if (file_exists($dir)) {
        return true;
    }

    $u = umask(0);
    $r = @mkdir($dir, 0777);
    umask($u);
    return $r;
}

function getHtml($url){
    $page = curl_file_get_contents($url);
    return $page;
}

function downloadImg($imgUrl,$foldername = 'img'){
    $picpath = DocumentRoot.'/'.$foldername;
    _mkdir($picpath);
    $filename= basename($imgUrl);
    $img = file_get_contents($imgUrl);
    if ($img) {
        file_put_contents($picpath.'/'.$filename, $img);
        return true;
    }
    return false;
}

function findPage($html){
    preg_match('//is', $html,$matches);
    return $matches;
}

function findList($html){
    preg_match_all('/

批量下载   妹子图自拍/is', $html,$matches); return $matches; } $p = isset($_GET['p'])?max(1,$_GET['p']):1; $home = getHtml('http://www.mzitu.com/share/comment-page-'.$p); $list = findList($home); echo "now downloading page ".$p."..."; if (is_array($list[1])) { foreach ($list[1] as $key => $value) { downloadImg($value); } } $page = findPage($home); if ($page[1] AND $page[1]>$p) { JsJump('/mzi.php?p='.$page[1]); }else{ exit("finished"); }