You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

84 lines
3.0 KiB

<?php
namespace App\Services;
use Log;
use QL\QueryList;
class FullSiteService {
public function fullSiteDownloadImage()
{
$dir = "/Volumes/WD/tmp/site/mm24.cc/simu/";
$files = scandir($dir);
dump("total files count is " . count($files));
// $files = array_slice($files, 38300);
$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 < 3776) {
// 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(100 * random_int(1000, 10000));
}
// dump($rt);exit;
}
}
}
public function replaceImagePath()
{
$dir = "/Volumes/WD/tmp/site/mm24.cc/beautyleg/";
// $files = scandir($dir);
// dump("total files count is " . count($files));
// foreach ($files as $file) {
// if ($file == "." || $file == ".." || $file == ".DS_Store") {
// continue;
// }
// dump($file);
// file_put_contents($dir . $file, str_replace("http://img.huangguogan.net", "..", file_get_contents($dir . $file)));
// exit;
// }
for ($i = 1; $i <= 46; $i++) {
if ($i == 1) {
$file = "4063.html";
} else {
$file = "4063_" . $i . ".html";
}
file_put_contents($dir . $file, str_replace("http://img.huangguogan.net", "..", file_get_contents($dir . $file)));
}
}
}