标签:
如何把get请求的参数转成字典 (Map)
urlparse.parse_qs(params) //str 需要转成字典的 请求参数 //{‘phone‘: [‘075988888888‘], ‘id‘: [‘10‘], ‘name‘: [‘\xe4\xb8\xad\xe6\x96\x87‘]}
获取一个网站的get 请求需要的参数
result = urlparse.urlparse(url)
urlparse.parse_qs(result.query)
例如 百度搜索
urls = ‘https://www.baidu.com/s?wd=%E5%87%BB%E6%B2%89&rsv_spt=1&rsv_iqid=0xc24a2e7700020d3c&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=18&rsv_sug1=23&rsv_sug7=101&rsv_sug2=0&inputT=6850&rsv_sug4=7802‘ result = urlparse.urlparse(urls)
结果是
result---> ParseResult(scheme=‘https‘, netloc=‘www.baidu.com‘, path=‘/s‘, params=‘‘, query=‘wd=%E5%87%BB%E6%B2%89&rsv_spt=1&rsv_iqid=0xc24a2e7700020d3c&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf- 8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=18&rsv_sug1=23&rsv_sug7=101&rsv_sug2=0&inputT=6850&rsv_sug4=7802‘, fragment=‘‘)
params =urlparse.parse_qs(result.query)
结果
params---> {‘wd‘: [‘\xe5\x87\xbb\xe6\xb2\x89‘], ‘rsv_spt‘: [‘1‘], ‘rsv_iqid‘: [‘0xc24a2e7700020d3c‘], ‘inputT‘: [‘6850‘], ‘f‘: [‘8‘], ‘rsv_enter‘: [‘1‘], ‘rsv_bp‘: [‘0‘], ‘rsv_idx‘: [‘2‘], ‘tn‘: [‘baiduhome_pg‘], ‘rsv_sug4‘: [‘7802‘], ‘rsv_sug7‘: [‘101‘], ‘rsv_sug1‘: [‘23‘], ‘issp‘: [‘1‘], ‘rsv_sug3‘: [‘18‘], ‘rsv_sug2‘: [‘0‘], ‘ie‘: [‘utf-8‘]}
标签:
原文地址:http://www.cnblogs.com/TomCzr/p/5859529.html