当前位置 : 主页 > 网络编程 > PHP >

纯粹跟风,用PHP下妹子图

来源:互联网 收集:自由互联 发布时间:2021-07-03
?phpphp_sapi_name() === 'cli' or exit('Please use the cli environemnt!' . PHP_EOL); $page = 1;$max_page = 5;$base_url = 'http://sexy.faceks.com/?page='; function getLinks($html){ preg_match_all('/a class="img" href="(.*)"[\\s]*img src=".*"
 
<?php
php_sapi_name() === 'cli' or exit('Please use the cli environemnt!' . PHP_EOL);
  
$page = 1;
$max_page = 5;
$base_url = 'http://sexy.faceks.com/?page=';
  
function getLinks($html){
    preg_match_all('/<a class="img" href="(.*)">[\\s]*<img src=".*" \\/>[\\s]*<\\/a>[\\s]*<\\/div>[\\s]*<div class="text"><p>(.*)<br \\/><\\/p>/', $html, $matchs);
    $links = array();
    if(count($matchs) > 2){
        foreach ($matchs[2] as $k => $v) {
            $links[$v] = $matchs[1][$k];
        }
    }
    return $links;
}
  
function getImgUrls($url){
    $html = file_get_contents($url);
    preg_match_all('<img src="(.*)">', $html, $matchs);
    return count($matchs) > 1 ? $matchs[1] : null;
}
  
function getImage($path, $url){
    preg_match('/==\\/(\\w+)\\.jpg/', $url, $match);
    $filepath = $path . DIRECTORY_SEPARATOR . $match[1] . '.jpg';
    ob_start();
    readfile($url);
    $img = ob_get_contents();
    ob_end_clean();
    $fp=@fopen($filepath, 'a') ;
    fwrite($fp, $img);
    fclose($fp) ;
}
  
while($page <= $max_page){
    echo '>>> Start download page ' . $page . PHP_EOL;
    $url = $base_url . $page;
    $html = file_get_contents($url);
    $links = getLinks($html);
    echo '>>> Find ' . count($links) . ' atlas' . PHP_EOL;
    foreach ($links as $k => $v) {
        $k = str_replace('&nbsp;', ' ', $k);
        if(!file_exists($k)){
            echo '>>> Make directory ' . $k . PHP_EOL;
            mkdir($k, 0755, true);
        }
        $img_urls = getImgUrls($v);
        foreach ($img_urls as $key => $value) {
            echo '>>> Downloading ' . $value . PHP_EOL;
            getImage($k, $value);
        }
    }
    $page++;
}

网友评论