importurllibparams=urllib.urlencode({"plato":1,"socrates":10,"sophokles":4,"arkhimedes":11})# Using GET methodpageText=urllib.urlopen("http://international-philosophy.com/greece?%s"%params).read()printpageText# Using POST methodpageText=urllib.urlopen("http://international-philosophy.com/greece",params).read()printpageText

The urllib module includes other functions that may be helpful when writing programs that use the internet:

>>>plain_text="This isn't suitable for putting in a URL">>>printurllib.quote(plain_text)This%20isn%27t%20suitable%20for%20putting%20in%20a%20URL>>>printurllib.quote_plus(plain_text)This+isn%27t+suitable+for+putting+in+a+URL

The urlencode function, described above converts a dictionary of key-value pairs into a query string to pass to a URL, the quote and quote_plus functions encode normal strings. The quote_plus function uses plus signs for spaces, for use in submitting data for form fields. The unquote and unquote_plus functions do the reverse, converting urlencoded text to plain text.