纯粹跟风,用PHP下妹子图
程序员文章站
2022-06-01 15:26:34
...
跳至
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('', $html, $matchs); return count($matchs) > 1 ? $matchs[1] : null; } function getImage($path, $url){ preg_match('/img\/(\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 $v) { $k = str_replace(' ', ' ', $k); // 如果是GBK编码的Windows,需要下面一行转换字符格式 // $k = mb_convert_encoding($k, 'gb2312', 'utf-8'); $k = strip_tags($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++; }