Bypass Login Captchas with Selenium: Cookie and Browser Profile Tricks
This guide shows how to circumvent login captchas in Python web automation by extracting cookies or launching browsers with saved profiles, covering driver setup, Chrome and Firefox configuration, and practical examples for sites like Baidu and Jianshu.
Bypass Login Methods
When using Python for web scraping or automated testing with Selenium, login captchas—especially text and image captchas with interference lines—are a common obstacle. Two main approaches can bypass them: capture and reuse the site’s cookies after a manual login, or launch the browser with a full user profile that already contains the necessary cookies and settings.
Add Cookie to Bypass Login
For example, after logging into a Baidu account, open the browser’s developer tools (F12), locate the www.baidu.com request, and copy the relevant cookie value highlighted in the screenshot.
Include this cookie in subsequent HTTP requests to access Baidu as an already‑logged‑in user.
Download Browser Driver
Selenium requires a driver that matches the browser version. Download the ChromeDriver and GeckoDriver and place them in the Python installation directory.
http://chromedriver.storage.googleapis.com/index.html https://github.com/mozilla/geckodriver/releases/Launch Chrome Browser to Bypass Login
Find Chrome’s profile directory by navigating to chrome://version/, remove the trailing \Default, and prepend --user-data-dir= to create the launch argument.
profile_directory = r'--user-data-dir=C:\Users\xxx\AppData\Local\Google\Chrome\User Data'Close all running Chrome instances before executing the script; otherwise, an error will occur. The full launch code (omitted for brevity) starts Chrome with the specified profile, preserving bookmarks and logged‑in accounts.
Launch Firefox Browser to Bypass Login
Locate the Firefox profile folder via Help → Troubleshooting Information → Profile Folder , copy the path, and set it in the script.
profile_path = r'C:\Users\guixianyang\AppData\Roaming\Mozilla\Firefox\Profiles\dvm6wqam.default'Running Selenium with this profile launches Firefox with the previously saved bookmarks and logged‑in Baidu account.
Bypass Graphic Captcha Sites
The same technique works for other sites, such as Jianshu. After logging in once and capturing the cookie, replace the target URL in the script with the Jianshu profile URL; the automated browser will retain the logged‑in state.
https://www.jianshu.com/u/52353ffa8b86With the login gate opened, you can proceed with web crawling, automated testing, or other tasks. Note that this method may not work on every website, but it is effective for many.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
