Created
August 25, 2017 09:24
-
-
Save laixintao/22b0d29cc48b5481c1d416cff51d2108 to your computer and use it in GitHub Desktop.
format chrome formdata to requests data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
$ python formdata.py "typeId=2&enTableName=SYJ_SXQYHMD_SYJ&searchName=&personField=QYMC&page=1&pageSize=10" | |
[ | |
('typeId', '2'), | |
('enTableName', 'SYJ_SXQYHMD_SYJ'), | |
('searchName', ''), | |
('personField', 'QYMC'), | |
('page', '1'), | |
('pageSize', '10'), | |
] | |
""" | |
from __future__ import unicode_literals | |
import sys | |
def main(): | |
if not sys.argv[1]: | |
print("Ussage: formdata typeId=2&test=string") | |
form_source = sys.argv[1] | |
pairs = form_source.split('&') | |
output_template = "[\n{}\n]" | |
fields = [] | |
for pair in pairs: | |
key, value = pair.split('=') | |
fields.append(" ('{}', '{}'),".format(key, value)) | |
print output_template.format('\n'.join(fields)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment