(4)编程将下面一个长字符串分割成相应的字典。 cookies = "anonymid=jy0ui55o-u6f6zd; depovince=GW; _r01_=1; JSESSIONID=abcMktGLRGjLtdhBk7OVw; ick_login=a9b557b8-8138-4e9d-8601-de7b2a633f80; _ga=GA1.2.1307141854.1562980962; _gid=GA1.2.201589596.1562980962; _c1=-100; first_login_flag=1; ln_uact=18323008898; ln_hurl=http://head.xiaonei.com/photos/0/0/men_main.gif; jebe_key=88f1340c-592c-4dd6-a738-128a76559f45%7Cad33b3c730fcdc8df220648f0893e840%7C1562981108370%7C1%7C1562981106763; jebe_key=88f1340c-592c-4dd6-a738-128a76559f45%7Cad33b3c730fcdc8df220648f0893e840%7C1562981108370%7C1%7C1562981106765; jebecookies=793eb32e-92c6-470d-b9d0-5f924c335d30|||||; _de=E77807CE44886E0134ABF27E72CFD74F; p=a00d65b1f779614cd242dc719e24c73e0; t=292ba8729a4151c1a357e176d8d91bff0; societyguester=292ba8729a4151c1a357e176d8d91bff0; id=969937120; xnsid=1700b2cc; ver=7.0; loginfrom=null; wp_fold=0"
时间: 2023-10-22 22:07:58 浏览: 74
一个将字符串分割的程序
3星 · 编辑精心推荐
可以使用 Python 来将该长字符串分割成相应的字典,具体代码如下:
```python
cookies = "anonymid=jy0ui55o-u6f6zd; depovince=GW; _r01_=1; JSESSIONID=abcMktGLRGjLtdhBk7OVw; ick_login=a9b557b8-8138-4e9d-8601-de7b2a633f80; _ga=GA1.2.1307141854.1562980962; _gid=GA1.2.201589596.1562980962; _c1=-100; first_login_flag=1; ln_uact=18323008898; ln_hurl=http://head.xiaonei.com/photos/0/0/men_main.gif; jebe_key=88f1340c-592c-4dd6-a738-128a76559f45%7Cad33b3c730fcdc8df220648f0893e840%7C1562981108370%7C1%7C1562981106763; jebe_key=88f1340c-592c-4dd6-a738-128a76559f45%7Cad33b3c730fcdc8df220648f0893e840%7C1562981108370%7C1%7C1562981106765; jebecookies=793eb32e-92c6-470d-b9d0-5f924c335d30|||||; _de=E77807CE44886E0134ABF27E72CFD74F; p=a00d65b1f779614cd242dc719e24c73e0; t=292ba8729a4151c1a357e176d8d91bff0; societyguester=292ba8729a4151c1a357e176d8d91bff0; id=969937120; xnsid=1700b2cc; ver=7.0; loginfrom=null; wp_fold=0"
# 将 cookies 字符串按照分号和空格来分割成一个列表
cookies_list = cookies.split("; ")
# 用字典来保存 cookies 中的键值对
cookies_dict = {}
# 遍历 cookies_list 列表,将每个元素按照等号来分割成键和值,并保存到 cookies_dict 字典中
for cookie in cookies_list:
cookie_split = cookie.split("=")
cookies_dict[cookie_split[0]] = cookie_split[1]
# 打印结果
print(cookies_dict)
```
运行代码后,输出结果为:
```
{'anonymid': 'jy0ui55o-u6f6zd', 'depovince': 'GW', '_r01_': '1', 'JSESSIONID': 'abcMktGLRGjLtdhBk7OVw', 'ick_login': 'a9b557b8-8138-4e9d-8601-de7b2a633f80', '_ga': 'GA1.2.1307141854.1562980962', '_gid': 'GA1.2.201589596.1562980962', '_c1': '-100', '...}
```
该结果为一个字典,其中保存了 cookies 中的所有键值对。
阅读全文