简体   繁体   English

我无法将 cookies 加载到无头镀铬 session + selenium (MacOS) 中

[英]I'm unable to load cookies into a headless chrome session + selenium (MacOS)

I'm trying to load cookies from a previous session into a new headless chrome session using selenium, if i try to load them using the same method i do with chrome but not in headless mode and taking a screen shot, it doesn't work because instead of being logged into the site takes me to the login screen. I'm trying to load cookies from a previous session into a new headless chrome session using selenium, if i try to load them using the same method i do with chrome but not in headless mode and taking a screen shot, it doesn't work因为我没有登录到该站点,而是将我带到了登录屏幕。

I've already tried passing via Options() a cookies folder or saving them with pickle and uploading once to the site like that:我已经尝试通过 Options() 传递一个 cookies 文件夹或用泡菜保存它们并像这样上传一次到网站:

options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get('site')

cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
    driver.add_cookie(cookie)

driver.refresh()

but neither one worked.但没有一个工作。

I have already searched if anyone has ever encountered my problem, but all the question is about loading cookies with selenium in a normal chrome session.我已经搜索过是否有人遇到过我的问题,但所有问题都是关于在普通镀铬 session 中使用 selenium 加载 cookies。

Thanks to all reply.感谢大家的回复。

You have to be on another site, load cookies and then redirect to the desired page.您必须在另一个站点上,加载 cookies 然后重定向到所需的页面。

options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get('other_site')

cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
    driver.add_cookie(cookie)

driver.get('site')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法在selenium中使用python请求会话cookie - I'm not able to use python requests session cookies in selenium WebDriverException:消息:无法将cookie从Session切换到Instagram上的Selenium的Chrome时设置cookie - WebDriverException: Message: unable to set cookie while switching cookies from Session to Selenium's Chrome on Instagram 使用 Python Selenium + Chrome 保存/加载 Cookies - Save/Load Cookies with Python Selenium + Chrome 带有硒的无头模式下的铬 - chrome in headless mode with selenium 在无头镀铬 Selenium 上检测到 - Detected on Headless Chrome Selenium 使用 chrome headless 和 selenium 下载 - Downloading with chrome headless and selenium Pycharm:使用Python的Selenium:无法使用无头Chrome浏览器查找Web元素 - Pycharm: Selenium with Python: Unable to find web elements using headless chrome 无法在非无头模式ChromeDriver和Chrome上运行Selenium测试 - Unable to run Selenium tests on non-headless mode ChromeDriver and Chrome 无法在 Windows 7 Enterprise 中运行 selenium chrome 无头模式 - unable to run selenium chrome headless mode in Windows 7 enterprise "Selenium 仅在使用无头铬(Python)时无法定位元素" - Selenium Unable to locate element only when using headless chrome (Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM