from ..GetImage import get_vc_image from ..ttshitu import base64_api, error_report from selenium.webdriver.common.action_chains import ActionChains from selenium.common.exceptions import NoSuchElementException import time def sign_in(driver): url = 'https://www.mcbbs.net/plugin.php?id=dc_signin' driver.get(url) if get_to_sign_in(driver): sign_in_vc(driver) def sign_in_vc(driver): image = get_image(driver) image = image.convert('RGB') image.save('D:\同步文件\课程文件\文档\mcbbs搞事\AutoTool\VerificationCode\image.jpg') img_path = 'D:\同步文件\课程文件\文档\mcbbs搞事\AutoTool\VerificationCode\image.jpg' result, rid = base64_api(uname='Shellmiao', pwd='sBif.9MMF8Pa', img=img_path) print(result) if click_vc_words(driver, get_points(result)): print("打码成功") else: print("打码失败") def get_points(result): groups = result.split('|') locations = [[int(number) for number in group.split(',')] for group in groups] return locations # 验证码的点击和确认 def click_vc_words(driver, locations, rid): element = driver.find_element_by_class_name('geetest_widget') for location in locations: # 因为笔记本缩放是250%,所以坐标要除以2.5 location[0] = location[0] * 0.5 location[1] = location[1] * 0.5 print(location) ActionChains(driver).move_to_element_with_offset(element, location[0], location[1]).click().perform() time.sleep(1) time.sleep(2) button = driver.find_element_by_class_name('geetest_commit_tip') time.sleep(2) ActionChains(driver).move_to_element(button).click().perform() time.sleep(2) try: button = driver.find_element_by_class_name('geetest_commit_tip') except NoSuchElementException: return True else: error_report(rid) sign_in_vc(driver) return False def get_to_sign_in(driver): if sign_in_button(driver): sign_in(driver) return True else: return False def sign_in_button(driver): try: button = driver.find_element_by_link_text('签到') except NoSuchElementException: return False else: ActionChains(driver).move_to_element(button).click().perform() return True def sign_in(driver): time.sleep(2) button = driver.find_element_by_id('emot_1') ActionChains(driver).move_to_element(button).click().perform() time.sleep(2) submit = driver.find_element_by_name('signpn') ActionChains(driver).move_to_element(submit).click().perform() def get_image(driver): time.sleep(2) element = driver.find_element_by_class_name('geetest_widget') vc_image = get_vc_image(element) return vc_image