SignIn.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. from ..GetImage import get_vc_image
  2. from ..ttshitu import base64_api, error_report
  3. from selenium.webdriver.common.action_chains import ActionChains
  4. from selenium.common.exceptions import NoSuchElementException
  5. import time
  6. def main_sign_in(driver):
  7. print('签到中')
  8. url = 'https://www.mcbbs.net/plugin.php?id=dc_signin'
  9. driver.get(url)
  10. print('正在前往签到界面')
  11. if get_to_sign_in(driver):
  12. sign_in_vc(driver)
  13. def sign_in_vc(driver):
  14. image = get_image(driver)
  15. image = image.convert('RGB')
  16. image.save('D:\同步文件\课程文件\文档\mcbbs搞事\AutoTool\VerificationCode\image.jpg')
  17. img_path = 'D:\同步文件\课程文件\文档\mcbbs搞事\AutoTool\VerificationCode\image.jpg'
  18. result, rid = base64_api(uname='Shellmiao', pwd='sBif.9MMF8Pa', img=img_path)
  19. print(result)
  20. if click_vc_words(driver, get_points(result), rid):
  21. print("打码成功")
  22. else:
  23. print("打码失败")
  24. def get_points(result):
  25. groups = result.split('|')
  26. locations = [[int(number) for number in group.split(',')] for group in groups]
  27. return locations
  28. # 验证码的点击和确认
  29. def click_vc_words(driver, locations, rid):
  30. element = driver.find_element_by_class_name('geetest_widget')
  31. for location in locations:
  32. # 因为笔记本缩放是250%,所以坐标要除以2.5
  33. location[0] = location[0] * 0.5
  34. location[1] = location[1] * 0.5
  35. print(location)
  36. ActionChains(driver).move_to_element_with_offset(element, location[0], location[1]).click().perform()
  37. time.sleep(1)
  38. time.sleep(1)
  39. button = driver.find_element_by_class_name('geetest_commit_tip')
  40. time.sleep(1)
  41. ActionChains(driver).move_to_element(button).click().perform()
  42. time.sleep(6)
  43. try:
  44. button = driver.find_element_by_class_name('geetest_commit_tip')
  45. except NoSuchElementException:
  46. return True
  47. else:
  48. error_report(rid)
  49. sign_in_vc(driver)
  50. return False
  51. def get_to_sign_in(driver):
  52. if sign_in_button(driver):
  53. sign_in(driver)
  54. return True
  55. else:
  56. return False
  57. def sign_in_button(driver):
  58. try:
  59. button = driver.find_element_by_link_text('签到')
  60. except NoSuchElementException:
  61. return False
  62. else:
  63. ActionChains(driver).move_to_element(button).click().perform()
  64. return True
  65. def sign_in(driver):
  66. time.sleep(2)
  67. button = driver.find_element_by_id('emot_1')
  68. ActionChains(driver).move_to_element(button).click().perform()
  69. time.sleep(2)
  70. submit = driver.find_element_by_name('signpn')
  71. ActionChains(driver).move_to_element(submit).click().perform()
  72. def get_image(driver):
  73. time.sleep(2)
  74. element = driver.find_element_by_class_name('geetest_widget')
  75. vc_image = get_vc_image(element)
  76. return vc_image