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/


沒有留言:

張貼留言

[Linux 常見問題] How to set a file size limit for a directory?

Source From   Here   Question   I   have a directory on my system which is used for a specific reason by applications and users , but I   d...