How to save and load cookies using Python + Selenium WebDriver

后端 未结 6 728
孤街浪徒
孤街浪徒 2020-11-22 07:52

How can I save all cookies in Python\'s Selenium WebDriver to a txt-file, then load them later? The documentation doesn\'t say much of anything about the getCookies function

6条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 08:23

    this is code I used in windows, It works.

     for item in COOKIES.split(';'):
                name,value = item.split('=',1)
                name=name.replace(' ','').replace('\r','').replace('\n','')
                value = value.replace(' ','').replace('\r','').replace('\n','')
                cookie_dict={  
                        'name':name,
                        'value':value,
                        "domain": "",  # google chrome
                        "expires": "",
                        'path': '/',
                        'httpOnly': False,
                        'HostOnly': False,
                        'Secure': False
                        }
                self.driver_.add_cookie(cookie_dict)
    

提交回复
热议问题