我正在使用selenium webdriver开发python程序,我需要在特定页面中登录并保持登录状态! 程序运行得很好,唯一的问题是cookie不能正常工作,程序需要登录的8次中有8次,为什么呢?我的代码是:
def start_browser():
global browser
#SERVER CONNECTION !!
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--lang=en')
chrome_options.add_argument('CHROME')
chrome_options.add_argument('user-data-dir=/root/hi_ryan_b/cookies') #this is the directory for the cookies
capabilities = chrome_options.to_capabilities()
browser = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=capabilities)
我不会'理解为什么很多时候它没有记录会话