2018年8月1日 星期三

[Linux 常見問題] Get url after curl is redirected

Source From Here 
Question 
I need to get the final url after a page redirect preferrably with curl or wget. For example http://google.com may redirect to http://www.google.com. 

The contents are easy to get(ex. curl --max-redirs 10 http://google.com -L), but I'm only interested in the final url (in the former case http://www.google.com). Is there any way of doing this by using only linux buildin tools? (command line only) 

How-To 
curl's -w option and the sub variable url_effective is what you are looking for. Something like: 
// -L Follow redirects 
// -s Silent mode. Don't output anything 
// -o FILE Write output to instead of stdout 
// -w FORMAT What to output after completion
 
# curl -Ls -o /tmp/abc.html -w 'Final URL=%{url_effective}\n' http://google.com 
Final URL=http://www.google.com/


沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...