python urlparse庫將application/x-www-form-urlencoded轉換爲字典

data of type application/x-www-form-urlencoded轉換爲字典形式


python官網有解釋:https://docs.python.org/2/library/urlparse.html

urlparse.parse_qs(qs[keep_blank_values[strict_parsing]])

Parse a query string given as a string argument (data of type application/x-www-form-urlencoded). Data are returned as a dictionary. The dictionary keys are the unique query variable names and the values are lists of values for each name.

The optional argument keep_blank_values is a flag indicating whether blank values in percent-encoded queries should be treated as blank strings. A true value indicates that blanks should be retained as blank strings. The default false value indicates that blank values are to be ignored and treated as if they were not included.

The optional argument strict_parsing is a flag indicating what to do with parsing errors. If false (the default), errors are silently ignored. If true, errors raise a ValueError exception.

Use the urllib.urlencode() function to convert such dictionaries into query strings.


參考:http://stackoverflow.com/questions/6877497/converting-x-www-form-urlencoded-query-string-to-a-dict

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章