Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix httrack跟随重定向_Unix_Download_Automation_Httrack - Fatal编程技术网

Unix httrack跟随重定向

Unix httrack跟随重定向,unix,download,automation,httrack,Unix,Download,Automation,Httrack,我尝试从用户提供的URL递归地镜像网页(当然有深度限制)。Wget没有捕获来自css/js的链接,所以我决定使用 我尝试像这样镜像一些站点: # httrack <http://onet.pl> -r6 --ext-depth=6 -O ./a "+*" #httrack-r6--ext depth=6-O./a“+*” 本网站使用重定向(301)至,httrack just 下载index.html页面,其中包含: <a HREF="onet.pl/index.html"

我尝试从用户提供的URL递归地镜像网页(当然有深度限制)。Wget没有捕获来自css/js的链接,所以我决定使用

我尝试像这样镜像一些站点:

# httrack <http://onet.pl> -r6 --ext-depth=6 -O ./a "+*"
#httrack-r6--ext depth=6-O./a“+*”
本网站使用重定向(301)至,httrack just 下载index.html页面,其中包含:

<a HREF="onet.pl/index.html" >Page has moved</a>

没别的了!当我跑步时:

# httrack <http://www.onet.pl> -r6 --ext-depth=6 -O ./a "+*"
#httrack-r6--ext depth=6-O./a“+*”
它符合我的要求

有没有办法让httrack跟踪重定向?目前,我只是在httrack的url中添加了“www.”+url,但这不是一个真正的解决方案(不包括所有用户案例)。有没有更好的linux网站镜像工具?

在主httrack上,一位开发人员说这是不可能的


正确的解决方案是使用另一个web镜像工具

您可以使用此脚本首先确定真正的目标url,然后针对该url运行httrack:

function getCorrectUrl($url) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_URL, $url);
    $out = curl_exec($ch);

    // line endings is the wonkiest piece of this whole thing
    $out = str_replace("\r", "", $out);

    // only look at the headers
    $headers_end = strpos($out, "\n\n");

    if ($headers_end !== false) {
        $out = substr($out, 0, $headers_end);
    }

    $headers = explode("\n", $out);

    foreach ($headers as $header) {
        if (substr($header, 0, 10) == "Location: ") {
            $target = substr($header, 10);
            return $target;
        }
    }

    return $url;
}

您能推荐任何遵循重定向的web镜像工具吗?