美文网首页
web自动化存cookie和读取cookie

web自动化存cookie和读取cookie

作者: Derex | 来源:发表于2019-06-23 22:00 被阅读0次
    import pickle
    from selenium import webdriver
    from time import sleep
    
    def setup_method(self):
        url = "https://qq.com/"
        self.driver = webdriver.Chrome()
        self.driver.get(url)
    
    def test_save_cookies():
        sleep(15)    #手动登录一次存cookie到pkl文件内
        pickle.dump(driver.get_cookies(), open("cookies.pkl","wb"))
    
    
    def load_cookies():
        cookies = pickle.load(open("cookies.pkl", "rb"))
        for cookie in cookies:
            driver.add_cookie(cookie)
    
    
    

    相关文章

      网友评论

          本文标题:web自动化存cookie和读取cookie

          本文链接:https://www.haomeiwen.com/subject/qvawqctx.html