<?php
|
|
namespace App\Services;
|
|
use Log;
|
|
use QL\QueryList;
|
|
|
|
class FullSiteService {
|
|
|
|
public function fullSiteDownloadImage()
|
|
{
|
|
$dir = "/Volumes/WD/tmp/site/mm24.cc/beautyleg/";
|
|
$files = scandir($dir);
|
|
$ql = QueryList::getInstance();
|
|
$i = 0;
|
|
foreach ($files as $file) {
|
|
$i++;
|
|
if ($i % 100 == 0) {
|
|
dump("current counter i is ". $i . "\n");
|
|
}
|
|
if ($file == "." || $file == ".." || $file == ".DS_Store") {
|
|
continue;
|
|
}
|
|
$htmlNum = substr($file, 0, 4);
|
|
if ((int)$htmlNum < 1072) {
|
|
continue;
|
|
}
|
|
if (str_contains($file, "html")) {
|
|
dump($file);
|
|
$ql = $ql->html(file_get_contents($dir. "/" . $file));
|
|
$rt = $ql->find('img')->attrs('src');
|
|
dump($rt);
|
|
foreach ($rt as $r) {
|
|
$filePathInfo = pathinfo($r);
|
|
// 获取相对路径
|
|
$path = parse_url($filePathInfo['dirname'])['path'];
|
|
if (str_contains($path, "..")) {
|
|
$localFilePath = $dir . $path . "/";
|
|
} else {
|
|
$localFilePath = $dir . "../" . $path . "/";
|
|
}
|
|
if (is_file($localFilePath . $filePathInfo["basename"])) {
|
|
continue;
|
|
}
|
|
if (!is_dir($localFilePath)) {
|
|
mkdir($localFilePath, 0777, true);
|
|
}
|
|
try {
|
|
$content = file_get_contents($r);
|
|
} catch (\Exception $e) {
|
|
Log::error("current url is " . $r . " trace: " . $e->getTraceAsString());
|
|
continue;
|
|
}
|
|
file_put_contents($dir . "../" . $path . "/" .$filePathInfo["basename"], $content);
|
|
usleep(1000 * random_int(1000, 10000));
|
|
}
|
|
// dump($rt);exit;
|
|
}
|
|
}
|
|
}
|
|
}
|