from PIL import Image, ImageEnhance, ImageFilter import pytesseract import requests # 下载验证码图片 captcha_url = 'https://yunxiu.f6car.cn/kzf6/login/captcha-image' # 替换为实际的验证码图片URL response = requests.get(captcha_url) with open('captcha.png', 'wb') as f: f.write(response.content) # 预处理验证码图片 def preprocess_image(image_path): image = Image.open(image_path) enhancer = ImageEnhance.Contrast(image) image = enhancer.enhance(2.0) enhancer = ImageEnhance.Brightness(image) image = enhancer.enhance(1.5) image = image.convert('L') image = image.point(lambda x: 0 if x < 128 else 255, '1') image.save('preprocessed_captcha.png') return image # 预处理验证码图片 preprocessed_image = preprocess_image('captcha.png') # 使用pytesseract识别验证码 captcha_text = pytesseract.image_to_string(preprocessed_image) print(f"识别的验证码为: {captcha_text}") # 登录信息 login_url = 'https://example.com/login' # 替换为实际的登录URL login_data = { 'username': 'your_username', 'password': 'your_password', 'captcha': captcha_text # 使用识别的验证码 }