Selenium从CookieJar添加Cookie

Pro*_*Fan 5 python selenium

我正在尝试将python请求会话cookie添加到我的selenium webdriver中.

到目前为止我已经尝试过了

for c in self.s.cookies : driver.add_cookie({'name': c.name, 'value': c.value, 'path': c.path, 'expiry': c.expires})

这段代码适用于PhantomJS,而不适用于Firefox和Chrome.

我的问题:

  1. Firefox和Chrome有没有特别的cookiejar迭代?
  2. 为什么它适用于PhantomJS?

Bar*_*art 5

for cookie in s.cookies:  # session cookies
    # Setting domain to None automatically instructs most webdrivers to use the domain of the current window
    # handle
    cookie_dict = {'domain': None, 'name': cookie.name, 'value': cookie.value, 'secure': cookie.secure}
    if cookie.expires:
        cookie_dict['expiry'] = cookie.expires
    if cookie.path_specified:
        cookie_dict['path'] = cookie.path

    driver.add_cookie(cookie_dict)
Run Code Online (Sandbox Code Playgroud)

检查这个是否有完整的解决方案https://github.com/cryzed/Selenium-Requests/blob/master/seleniumrequests/request.py