python selenium和requests获取cookies并格式化

宋志学
2023-12-01

selenium获取cookies并格式化

cookie = driver.get_cookies()
cookie_parse = dict()
for ck in cookie:
    cookie_parse[ck['name']] = ck['value']
    # 将字典拼成字符串
cookies = ''.join([str(k) + '=' + str(v) + ';' for k, v in cookie_parse.items()])

# 一行代码
# cookie = {c["name"]: c["value"] for c in driver.get_cookies()}

requests获取cookies转字典

在这里插入代码片
 类似资料: