def write_cookie(self, cookie): try: with open("cookies%s" % self.uid, "wb+") as f: pickle.dump(cookie, f) except Exception as e: get_logger().error("writecookie Error,here are details{}".format(traceback.format_exc())) def read_cookie(self): cookiesfilepath = "cookies%s" % self.uid if os.path.exists(cookiesfilepath): ctime = os.path.getctime(cookiesfilepath) create = datetime.datetime.fromtimestamp(ctime) + datetime.timedelta(days=+1) nowdate = datetime.datetime.now() if (nowdate > create): os.remove(cookiesfilepath) return False else: try: with open("cookies%s" % self.uid, "rb") as fs: data = pickle.load(fs) return data except: get_logger().info("Cookies Not In Disk") return False # 初始化url