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