Skip to content

Instantly share code, notes, and snippets.

@Kevinstronger
Created February 27, 2014 05:51
Show Gist options
  • Save Kevinstronger/9245089 to your computer and use it in GitHub Desktop.
Save Kevinstronger/9245089 to your computer and use it in GitHub Desktop.
How to use urlparse
#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