Get parameters from URL using CGI

abcd codecraig at gmail.com
Sat Feb 18 22:27:42 EST 2006


Ian Leitch wrote:
> >>> 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'}


Ian,  thanks for the reply, but that is not what I need to do.  Inside
foo.cgi how can I parse out the values given in the URL?

So if you visit: http://www.somesite.com/cgi-bin/foo.cgi?valA=1&valB=2
.....I want the script, foo.cgi to print out the parameters and their
values.  It's dynamic so the values are url wont be the same all the
time.  How do i get the URL from the script?  does this make sense?

So I'm thinking foo.cgi will look like
[code]
url = getTheFullURL()
parse(url)

def parse(url):
    # parse the parameter names and values
[/code]




More information about the Python-list mailing list