Interface return a json. json in turn contains a string, the string encoding and there, then how are we to intercept a variety of value you want it?
Gets a string from json returned interface in ways please refer here: https://www.cnblogs.com/Zhan-W/p/11876366.html
Next on the record about how the results have been intercepted want to get out from a string of:
Objectives: args taken from this string value, but the value args comprising a plurality of values, while there are encoding
eg: https://www.xxxxxxx.com/new/#/register/h5?ProjectType=0&args=eyJ0ZW5hbnROYW1lIjoiV01TXzUyMF8zODk0Iiwic2hhcmVQYXJhbSI6Im4zNGdDLzR1RnpNTkY0RVl5eWhUY3U4SlNmQ3JCbTExZGpQeE9uQld0Z2wyQXFJQmdFSGpsUT09In0%3d
Steps are as follows:
1, the first decoding
# __*__coding:utf-8 __*__
import urllib.parse
import base64
import json
# The args string S is encoded in the
S = " https://test.xxxxxx.com/new/#/register/h5?ProjectType=0&args=eyJ0ZW5hbnROYW1lIjoiV01TXzUyMF8zODk0Iiwic2hhcmVQYXJhbSI6Im4zNGdDLzR1RnpNTkY0RVl5eWhUY3U4SlNmQ3JCbTExZGpQeE9uQld0Z2wyQXFJQmdFSGpsUT09In0%3d "
# to decode the string S
= url_parameter_1 urllib.parse.unquote (S)
Print ( " decoded url_parameter_1 values: " , url_parameter_1)
Decoded result is:
2, sliced
# To the decoded string S from the field "args =" slice by using a Split ()
url_parameter_2 = url_parameter_1.split ( " args = " )
Print ( " sliced url_parameter_2 values: " , url_parameter_2)
# viewing slices after url_parameter_2 type
Print ( " url_parameter_2 value of type: " , of the type (url_parameter_2)) # is a list type
Results sections as follows:
3, the value
# Get the value of the sliced
url_parameter_3 url_parameter_2 = [. 1 ]
Print ( " url_parameter_3 values: " , url_parameter_3)
The value of the results:
To have been here this long list cents wanted to get out, but he bit through base64 encoded performs decode:
4, decoding
url_parameter_4 = base64.b64decode(url_parameter_3)
解码后的结果为:
此时获取到的url_parameter_4的值类型为:bytes,其实是不便于我们获取shareParam这个值的,
5、转换类型
url_parameter_5 = json.loads(url_parameter_4)
print("转换类型后的url_parameter_5结果为:",url_parameter_5)
转换后的结果为 :
现在已经是个字典了 ,我们按照获取字典的值的方法去拿到shareParam的值
6、获取字典值
url_parameter_6 = url_parameter_5["shareParam"]
print(url_parameter_6)
获取的字典值为 :
这样就拿到了我最终想要的这个值,以供其他接口使用