Fetching HTTP GET variables in Python

后端 未结 2 1130
故里飘歌
故里飘歌 2021-01-05 11:25

I\'m trying to set up a HTTP server in a Python script. So far I got the server it self to work, with a code similar to the below, from here.

from BaseHTTPSe         


        
相关标签:
2条回答
  • 2021-01-05 11:55

    Import urlparse and do:

    def do_GET(self):
        qs = {}
        path = self.path
        if '?' in path:
            path, tmp = path.split('?', 1)
            qs = urlparse.parse_qs(tmp)
        print path, qs
    
    0 讨论(0)
  • 2021-01-05 12:06

    urlparse.parse_qs()

    print urlparse.parse_qs(os.environ['QUERY_STRING'])
    

    Or if you care about order or duplicates, urlparse.parse_qsl().

    Import in Python 3: from urllib.parse import urlparse

    0 讨论(0)
提交回复
热议问题