loading cookies from selenium to mechanize with cookielib loading cookies from selenium to mechanize with cookielib selenium selenium

loading cookies from selenium to mechanize with cookielib


if you print the cookies collected by Selenium and compare it to a cookie collected by mechanize/cookielib you will notice they use different formats.

To overcome this you can try something like this (you may need to modify it a bit, to fit your needs. but you get the general idea):

cj = cookielib.LWPCookieJar()for s_cookie in cookie:    cj.set_cookie(cookielib.Cookie(version = 0, name = s_cookie['name'], value = s_cookie['value'], port = '80', port_specified = False, domain = s_cookie['domain'], domain_specified = True, domain_initial_dot = False, path = s_cookie['path'], path_specified = True, secure = s_cookie['secure'], expires = s_cookie['expiry'], discard = False, comment = None, comment_url = None, rest = None, rfc2109 = False))

A bit more fancy solution would be to iterate over the selenium cookies and make a dictionary with name : value pairs