通常我们将字典转换为query string 的时候非常方便,Python提供内置方法;但是反过来却没有内置方法,但是我们可以这样:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
a = "https://mp.weixin.qq.com/s?__biz=MzIzNzA4NDk3Nw==&mid=2457736062&idx=1&sn=82b59e93f8648cf7343cd2b4fb7ecc41&chksm=ff44bb20c8333236f1798f3790a7886088e58871fba315c5ea319a6772c7b91211b1608421b2&mpshare=1&scene=1&srcid=0615ejI92JB3sw1rj0mVg72L#rd"
import urllib
query = urllib.parse.urlparse(a).query
dict([(k, v[0]) for k, v in urllib.parse.parse_qs(query).items()])
Out[5]: 
{'__biz': 'MzIzNzA4NDk3Nw==',
 'chksm': 'ff44bb20c8333236f1798f3790a7886088e58871fba315c5ea319a6772c7b91211b1608421b2',
 'idx': '1',
 'mid': '2457736062',
 'mpshare': '1',
 'scene': '1',
 'sn': '82b59e93f8648cf7343cd2b4fb7ecc41',
 'srcid': '0615ejI92JB3sw1rj0mVg72L'}

以上完毕!