纯粹跟风,用PHP下妹子图

最近大家都在下妹子图,反正闲了一下,就跟风用PHP也下一下

<?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++;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值