即使在 dyno 每天重新启动后,我如何保持自己登录到 heroku(chromedriver)?

how do i keep myself logged in heroku (chromedriver) even after dyno restarts everyday?

我已经用 selenium-python 和 运行 通过 Heroku 制作了一个机器人, 机器人每天登录 Instagram 并执行 activity, 现在这里的问题是 Heroku -dynos 每天重新启动..所以机器人必须每天登录 Instagram。 我想在 ChromeDriver 中保存我的登录会话,这样 即使 Dynos 重新启动,机器人也不需要登录 ..我该怎么做这个?

here is the code i am using to declare driver

class Account:
    def __init__(self,username,password,dm,comments,user):
        self.user=user
        self.username=username
        self.password=password
        options = webdriver.ChromeOptions()
        options.add_argument('--no-sandbox')
        options.add_argument("--disable-dev-shm-usage")
        options.add_argument("--disable-gpu")
        try:
            driver = webdriver.Chrome(options=options)
            self.driver=driver
        except:
            traceback.print_exc()
        self.followedtoday=[]
        self.startofcode=time.time()
        self.resetvars()
        self.commentarray=commentarray
        self.searcharray=searcharray
        self.message=dm
        self.comments=comments
        self.visit=[]
    self.hours=0

def login(self):
        self.driver.get('https://www.instagram.com/')
        print('logging in account of ',self.username)
        try:
            #9 seconds to load page
            wait()
            wait()
            print (self.driver.page_source.encode("utf-8"))
            username = self.driver.find_element_by_xpath("//input[@aria-label='{}']".format('Phone number, username, or email'))                                                    
            username.send_keys(self.username)
            password = self.driver.find_element_by_xpath("//input[@aria-label='{}']".format('Password'))                                                       
            password.send_keys(self.password)
            #wait to type
            wait()
            wait()
            sign_in_button = self.driver.find_element_by_xpath("//*[text()='{}']".format('Log In'))
            sign_in_button.click()
            wait()

来自 Chrome 能力 documentations

Use custom profile (also called user data directory)
By default, ChromeDriver will create a new temporary profile for each session.

因此您需要通过 user-data-dir 创建并加载自定义配置文件。

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");

作为基础,但当然可以根据需要进行调整以使用实现。 您可以通过浏览至 chrome://version

检查已加载的配置文件

使用options.add_argument('--profile-directory=<profile>')加载配置文件应该也可以。