使用代码完成极验验证码的识别,需要了解一下几点:
定义CrackGeetest()类,该类中定义通过该验证码的方法。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time
from io import BytesIO
from PIL import Image
from selenium.webdriver import ActionChains
from selenium.common.exceptions import TimeoutException
import random
"""[summary]
使用极验滑动验证码的官网为例,若没有账号先注册。
"""
EMAIL = '[email protected]'
PASSWORD = '密码'
class CrackGeetest():
"""[summary]
初始化
"""
def __init__(self):
self.url = 'https://account.geetest.com/login'
self.browser = webdriver.Chrome()
self.wait = WebDriverWait(self.browser, 5)
self.email = EMAIL
self.password = PASSWORD
def __del__(self):
self.browser.close()
def open(self):
"""[summary]
输入用户及密码
"""
self.browser.get(self.url)
email = self.wait.until(EC.presence_of_element_located((By.ID, 'email')))
password = self.wait.until(EC.presence_of_element_located((By.ID, 'password')))
email.send_keys(self.email)
password.send_keys(self.password)
def get_geetest_button(self):
"""[summary]
获取初始验证按钮
返回按钮对象
"""
button = self.wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'geetest_radar_tip')))
return button
# 余下代码见GitHub