SignIn.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from ..GetImage import get_vc_image
  2. from ..ttshitu import base64_api
  3. from selenium.webdriver.common.action_chains import ActionChains
  4. import time
  5. def sign_in_vc(driver):
  6. url = 'https://www.mcbbs.net/plugin.php?id=dc_signin'
  7. driver.get(url)
  8. get_to_sign_in(driver)
  9. image = get_image(driver)
  10. image = image.convert('RGB')
  11. image.save('D:\同步文件\课程文件\文档\mcbbs搞事\AutoTool\VerificationCode\image.jpg')
  12. img_path = 'D:\同步文件\课程文件\文档\mcbbs搞事\AutoTool\VerificationCode\image.jpg'
  13. result = base64_api(uname='Shellmiao', pwd='sBif.9MMF8Pa', img=img_path)
  14. print(result)
  15. click_vc_words(driver, get_points(result))
  16. def get_points(result):
  17. groups = result.split('|')
  18. locations = [[int(number) for number in group.split(',')] for group in groups]
  19. return locations
  20. # 验证码的点击和确认
  21. def click_vc_words(driver, locations):
  22. element = driver.find_element_by_class_name('geetest_widget')
  23. for location in locations:
  24. # 因为笔记本缩放是250%,所以坐标要除以2.5
  25. location[0] = location[0] * 0.5
  26. location[1] = location[1] * 0.5
  27. print(location)
  28. ActionChains(driver).move_to_element_with_offset(element, location[0], location[1]).click().perform()
  29. time.sleep(1)
  30. time.sleep(2)
  31. button = driver.find_element_by_class_name('geetest_commit_tip')
  32. ActionChains(driver).move_to_element(button).click().perform()
  33. time.sleep(2)
  34. def get_to_sign_in(driver):
  35. sign_in_button(driver)
  36. sign_in(driver)
  37. def sign_in_button(driver):
  38. button = driver.find_element_by_link_text('签到')
  39. ActionChains(driver).move_to_element(button).click().perform()
  40. def sign_in(driver):
  41. time.sleep(2)
  42. button = driver.find_element_by_id('emot_1')
  43. ActionChains(driver).move_to_element(button).click().perform()
  44. time.sleep(2)
  45. submit = driver.find_element_by_name('signpn')
  46. ActionChains(driver).move_to_element(submit).click().perform()
  47. def get_image(driver):
  48. time.sleep(2)
  49. element = driver.find_element_by_class_name('geetest_widget')
  50. vc_image = get_vc_image(element)
  51. return vc_image