I built a Python script that creates a session and makes several HTTP requests using the requests library. Everything works fine but now I need to switch to using Selenium WebDriver (both regular and headless mode) while keeping all the session data intact.
The problem is that when I launch the browser with Selenium, it starts fresh without any of the cookies or session information from my previous requests. I want the browser to continue with the same logged-in state and session data that was established earlier in my script.
Is there a way to transfer or share session data between requests and Selenium WebDriver so I can seamlessly continue my automation workflow in the browser?
I’ve hit this exact problem tons of times in production. Cookie transfer works, but it’s a pain with complex auth flows or when you need to scale.
What’s way more reliable? Automation that handles both HTTP requests and browser sessions together. Skip the manual juggling between requests and Selenium - set up a flow that keeps sessions alive without the cookie extraction headache.
Best part is you can run everything in one workflow. Initial login requests, browser automation, all of it. No more fighting domain restrictions, cookie formats, or session timeouts.
I use this when I need API auth first, then browser automation for complex stuff. Works great and cuts debugging time in half.
Cookie transfer works, but you’ve got to do it right. I hit problems when sessions had CSRF tokens or other dynamic stuff that requests and Selenium handled differently. What fixed it for me was grabbing not just cookies but also session headers and tokens from the requests session before switching to Selenium. Then I used execute_script to set localStorage and sessionStorage values along with the cookies. Make sure your requests session and Selenium driver have identical user agents - some sites will kill your session otherwise. Timing’s crucial too. Transfer everything right after your last successful request, don’t wait around.
yep, same issue here! what i did was extract cookies from requests using session.cookies and then fed them into selenium via driver.add_cookie(). just make sure to navigate to the correct domain to avoid errors!