【问题标题】:httrack follow redirectshttrack 跟随重定向
【发布时间】:2012-08-11 21:26:06
【问题描述】:

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

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

# httrack <http://onet.pl> -r6 --ext-depth=6 -O ./a "+*"

本网站使用重定向(301)到http://www.onet.pl:80,httrack 只是 下载 index.html 页面:

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

仅此而已!当我跑步时:

# httrack <http://www.onet.pl> -r6 --ext-depth=6 -O ./a "+*"

它做我想做的事。

有没有办法让 httrack 跟随重定向?目前我只是将 "www."+url 添加到 httrack 的 URL 中,但这不是一个真正的解决方案(不涵盖所有用户案例)。有没有更好的 linux 网站镜像工具?

【问题讨论】:

    标签: unix download automation httrack


    【解决方案1】:

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

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

    【讨论】:

    • 您能推荐任何遵循重定向的网络镜像工具吗?
    【解决方案2】:

    您可以使用此脚本首先确定真正的目标 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;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-01-05
      • 2020-04-15
      • 1970-01-01
      • 2023-03-12
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      相关资源
      最近更新 更多