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))); } } }