def get_url(url): browser.get(url) input = browser.find_element_by_css_selector("#J-userName") input.send_keys("15215966137") pwd = browser.find_element_by_css_selector("#J-password") pwd.send_keys("!980723sqk") img = browser.find_element_by_css_selector("#J-loginImg") src = img.get_attribute('src') request.urlretrieve(src, './img_1.png') from YDMHTTP import decode result = decode('img_1.png', 6701) print('选项', result) # 返回的是字符串 # 根据识别结果点击图片 position_list = [(40, 70), (110, 70), (180, 70), (252, 70), (40, 150), (110, 150), (180, 150), (250, 150)] if result != '看不清': for position in result: ActionChains(window).move_to_element_with_offset( img_ele, position_list[int(position) - 1][0], position_list[int(position) - 1][1]).click().perform() # 点击登录按钮 login_button = window.find_element_by_id('J-login') login_button.click()
# -*- coding: utf-8 -*- import sys sys.path.insert(1, r"YDMHTTP.py") from YDMHTTP import decode print(decode('demo.png', codetype=6701))
x2 = x1 + login_img_element.size["width"] * scale y2 = y1 + login_img_element.size["height"] * scale cut_info = (x1, y1, x2, y2) # 把全屏图片构建成全屏图片操作对象 full_img = Image.open(BytesIO(full_img_data)) # 通过截图信息对象截取图片 cut_img = full_img.crop(cut_info) # 把图片保存到本地 cut_img.save('demo.png') # 将验证图片发送到打码平台 result = decode('demo.png', codetype=6701) # 定义八个点击坐标点 positions = [(7.30 * 25, 140), (10.58 * 25, 140), (13.83 * 25, 140), (17.11 * 25, 140), (7.30 * 25, 250), (10.58 * 25, 250), (13.83 * 25, 250), (17.05 * 25, 250)] # 模拟点击坐标 for num in result: position = positions[int(num) - 1] # 动作对象 ActionChains(browser).move_to_element_with_offset( login_img_element, position[0] / 2, position[1] / 2).click().perform() # 点击登录 browser.find_element_by_id("J-login").click()
y1 = login_img_element.location["y"] * scale x2 = x1 + login_img_element.size["width"] * scale y2 = y1 + login_img_element.size["height"] * scale cut_info = (x1, y1, x2, y2) # 通过计算出的截图图位置在全屏图片中截取所需要的图片 # 把全屏图片构建成全屏图片操作对象 full_img = Image.open(BytesIO(full_img_data)) # 通过截图信息对象截图图片 cut_img = full_img.crop(cut_info) # 把图片保存到本地 cut_img.save('cut_img.png') # 发送打码平台获取数字 result = decode('cut_img.png', codetype=6701) print(result) # 定义8个点击坐标点 positions = [(80, 140), (230, 140), (380, 140), (530, 140), (80, 280), (230, 280), (380, 280), (530, 280)] # 模拟点击坐标 for num in result: position = positions[int(num) - 1] # ActionChains 动作对象 ActionChains(browser).move_to_element_with_offset( login_img_element, position[0] / 2, position[1] / 2).click().perform() # 点击登录 browser.find_element_by_id('J-login').click()
#!/usr/bin/python3 # -*- coding: utf-8 -*- from YDMHTTP import decode # print(decode('test2.png',codetype=3000)) print(decode('test3.png', codetype=6701))
# 输入账号 input_account = window.find_element_by_id('J-userName') input_account.send_keys('账号') # 输入密码 input_password = window.find_element_by_id('J-password') input_password.send_keys('密码') # 获取验证码图片 img_ele = wait.until(EC.presence_of_element_located((By.ID,'J-loginImg'))) src = img_ele.get_attribute('src') from urllib import request request.urlretrieve(src,'./img_1.png') print('图片已保存') # 发送到打码平台 from YDMHTTP import decode result = decode('img_1.png',6701) print('选项',result) # 返回的是字符串 # 根据识别结果点击图片 position_list = [(40,70), (110,70),(180,70),(252,70),(40,150),(110,150),(180,150),(250,150)] if result != '看不清': for position in result: ActionChains(window).move_to_element_with_offset(img_ele,position_list[int(position)-1][0],position_list[int(position)-1][1]).click().perform() # 点击登录按钮 login_button = window.find_element_by_id('J-login') login_button.click()