我需要在页面重定向后获得最终的URL,最好是使用curl或wget。
例如,可能会重定向到。
内容很容易获得(例如:curl --max-redirs 10 http://google.com -L),但我只对最后的url感兴趣(在前面的例子中是http://www.google.com)。
有没有办法只使用Linux内置的工具来做到这一点?(仅限命令行)
发布于 2019-11-25 17:45:18
你能试一下吗?
#!/bin/bash
LOCATION=`curl -I 'http://your-domain.com/url/redirect?r=something&a=values-VALUES_FILES&e=zip' | perl -n -e '/^Location: (.*)$/ && print "$1\n"'`
echo "$LOCATION"注意:当您执行命令curl时,-I http://your-domain.com必须在命令中使用单引号,如curl -I 'http://your-domain.com'
https://stackoverflow.com/questions/3074288
复制相似问题