我正在使用Selenium登录帐户。登录后,我想保存该会话并在下次运行python脚本时再次访问该会话,因此不必再次登录。基本上,我想让chrome驱动程序像保存所有cookie /会话的真实Google chrome一样工作。这样,我不必每次运行都登录到该网站。
browser.get("https://www.website.com")
browser.find_element_by_xpath("//*[@id='identifierId']").send_keys(email)
browser.find_element_by_xpath("//*[@id='identifierNext']").click()
time.sleep(3)
browser.find_element_by_xpath("//*[@id='password']/div[1]/div/div[1]/input").send_keys(password)
browser.find_element_by_xpath("//*[@id='passwordNext']").click()
time.sleep(5)
这是我使用的解决方案:
# I am giving myself enough time to manually login to the website and then printing the cookie
time.sleep(60)
print(driver.get_cookies())
# Than I am using add_cookie() to add the cookie/s that I got from get_cookies()
driver.add_cookie({'domain': ''})
这可能不是实现它的最佳方法,但它正在做我一直在寻找的事情
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句