我在 selenium-python 中制作了一个机器人并通过 Heroku 运行它,该机器人每天登录 Instagram 并进行活动,现在这里的问题是 Heroku -dynos 每天都会重新启动..所以机器人必须每天登录 Instagram。 我想在 ChromeDriver 中保存我的登录会话,这样即使 Dynos 重新启动,机器人也不需要登录..我该怎么做?
这是我用来声明驱动程序的代码
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()