Bypass Captchas with Python: Selenium + Chaojiying Tutorial

This article walks through a Python solution for automatically solving web‑page captchas by capturing the image with Selenium, sending it to the Chaojiying service, and retrieving the decoded text, complete with sample code and execution results.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Bypass Captchas with Python: Selenium + Chaojiying Tutorial

1. Introduction

Hello, I'm PiPi. In a Python community I was asked about handling captchas during web crawling, so I’m sharing a third solution after two earlier methods.

2. Implementation

The approach uses Selenium to locate the captcha image, then uploads it to the third‑party service Chaojiying for recognition. The returned text can be used to complete login automatically.

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from PIL import Image
import ddddocr
from chaojiying import Chaojiying_Client

ocr = ddddocr.DdddOcr()

options = webdriver.ChromeOptions()
options.add_argument('user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36')
options.add_argument('--disable-blink-features=AutomationControlled')

driver = webdriver.Chrome(options=options)

# Open target page
driver.get('https://sol.sinosure.com.cn')
time.sleep(3)

# Capture captcha
img = driver.find_element(By.XPATH, '//*[@id="codeimage"]').screenshot_as_png
chaojiying = Chaojiying_Client('666', '666', '923043')
print(chaojiying.PostPic(img, 1902))  # returns a dict

dic = chaojiying.PostPic(img, 1902)
verify_code = dic["pic_str"]
print(verify_code)

Running the script successfully prints the decoded captcha string.

3. Conclusion

The article presents a practical Python method for solving captchas using Selenium and the Chaojiying platform, adding a third option to the previously discussed two methods.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

automationWeb ScrapingSeleniumCaptcha SolvingChaojiying
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.