Caltech Library logo

Using urlparse

With no options returns “http.commy/page.html”

    urlparse http://example.com/my/page.html

Get protocol. Returns “http”.

    urlparse -protocol http://example.com/my/page.html

Get host or domain name. Returns “example.com”.

    urlparse -host http://example.com/my/page.html

Get path. Returns “/my/page.html”.

    urlparse -path http://example.com/my/page.html

Get dirname. Returns “my”

    urlparse -dirname http://example.com/my/page.html

Get basename. Returns “page.html”.

    urlparse -basename http://example.com/my/page.html

Get extension. Returns “.html”.

    urlparse -extname http://example.com/my/page.html

Without options urlparse returns protocol, host and path fields separated by a tab.

example files