I’d like to write a function that, given a URL, returns the name of the file downloaded by wget URL.
I don’t understand the behavior of wget very well. If I do wget on python.org, www.python.org, http://www.python.org, or http://www.python.org/, the name of the file downloaded is index.html.
However, if I do www.python.org/about, the name of the file downloaded is about, instead of index.html.
The reason your
wgetfetchesindex.htmlin the first cases is because that’s the default “home page” that the server points to.python.org,www.python.org,http://www.phython.org, andhttp://www.python.org/aren’t files, so the server pointswgettoindex.html. It points your browser there, too, though you don’t usually see it.www.python.org/aboutis a different page, so it makes sense that the file it downloads has a different name.Might I recommend the man page for wget if you want to know how it works? If it’s the name of the downloaded file that concerns you, you have the option to change it via the
-Ooption.