Get parameters from URL using CGI

Ian Leitch port001 at gentoo.org
Sat Feb 18 16:08:59 EST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

abcd wrote:
> i want to create a CGI script which simply prints out values given via
> the URL (such as when a GET is performed).
> 
> So if I have a script named, foo.cgi ....and I access it by going to:
> 
> http://www.somesite.com/cgi-bin/foo.cgi?name=john&age=90
> 
> I want foo.cgi to print out:
> name: john
> age: 90
> 
> 
> how do i get the values from the URL like that?
> 
> thanks

>>> from urlparse import urlparse
>>> dict([n for n in [i.split('=') for i in
urlparse('http://www.somesite.com/cgi-bin/foo.cgi?name=john&age=90')[4].split('&')]])
{'age': '90', 'name': 'john'}
>>>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFD94zrefZ4eWAXRGIRAlEhAJ49x7kaIe/VcU5DUbt8bv9tQCNrmQCfWOED
tmkTISLqzIKDz2c4mfR6+k8=
=OMOX
-----END PGP SIGNATURE-----



More information about the Python-list mailing list