我需要在页面重定向后获得最终URL,最好使用curl或wget.
例如,100可以重定向到101.
内容很容易获取(例如curl --max-redirs 10 http://google.com -L
),但我只对最终的url感兴趣(在前一个例子中是http://www.google.com).
有没有办法只使用Linux内置工具来实现这一点?(仅限命令行)
我需要在页面重定向后获得最终URL,最好使用curl或wget.
例如,100可以重定向到101.
内容很容易获取(例如curl --max-redirs 10 http://google.com -L
),但我只对最终的url感兴趣(在前一个例子中是http://www.google.com).
有没有办法只使用Linux内置工具来实现这一点?(仅限命令行)
curl
是-w
option,子变量url_effective
是你的本来面目
差不多
curl -Ls -o /dev/null -w %{url_effective} http://google.com
更多信息
-L Follow redirects -s Silent mode. Don't output anything -o FILE Write output to <file> instead of stdout -w FORMAT What to output after completion
More
您可能还想添加-I
(大写i
),这将使命令不会下载任何"body",但它随后也会使用HEAD方法,这不是问题所包含的内容,并且可能会改变服务器的功能.有时,服务器对HEAD的响应并不好,即使它们对HEAD的响应很好.