Created
February 27, 2014 05:51
-
-
Save Kevinstronger/9245089 to your computer and use it in GitHub Desktop.
How to use urlparse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
import urlparse | |
URLscheme = "http" | |
URLlocation = "www.python.org" | |
URLpath = "lib/module-urlparse.html" | |
modList = ("urllib", "urllib2", "httplib", "cgilib") | |
parsedTuple = urlparse.urlparse("http://www.google.com/search?hl=en&q=urlparse&btnG=Google+Search") | |
print parsedTuple | |
unparsedURL = urlparse.urlunparse((URLscheme, URLlocation, URLpath, '', '', '')) | |
print unparsedURL | |
for mod in modList: | |
newURL = urlparse.urljoin(unparsedURL, "module-%s.html" % (mod)) | |
print newURL | |
newURL = urlparse.urljoin(unparsedURL,"module-urllib2/request-objects.html") | |
print newURL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment