Selenium与requests相互更换cookies
selenium获取cookies给requests
1 | # 登录后, 从selenium中获取cookies |
法一: session
1
2
3
4
5# 创建一个session的请求对象
s = requests.session()
# 遍历
for cookie in cookies:
s.cookies.set(cookies['name'], cookies['value'])法二: header
1
2
3
4
5
6# 请求头中cookies键的值
cookiestr = ''
# 连接有效cookies值
for cookie in cookies:
cookiestr = cookiestr + cookies['name'] + '=' + cookies['value'] + ';' + ' '
headers['cookies'] = cookiestr
requests获取cookies给selenium
1 | # 创建一个session的请求对象 |