SignIn.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. temp = ActionChains(driver).move_to_element_with_offset(element, location[0], location[1])
  37. time.sleep(2)
  38. temp.click().perform()
  39. time.sleep(1)
  40. time.sleep(1)
  41. button = driver.find_element_by_class_name('geetest_commit_tip')
  42. time.sleep(1)
  43. ActionChains(driver).move_to_element(button).click().perform()
  44. time.sleep(6)
  45. try:
  46. button = driver.find_element_by_class_name('geetest_commit_tip')
  47. except NoSuchElementException:
  48. return True
  49. else:
  50. error_report(rid)
  51. sign_in_vc(driver)
  52. return False
  53. def get_to_sign_in(driver):
  54. if sign_in_button(driver):
  55. sign_in(driver)
  56. return True
  57. else:
  58. return False
  59. def sign_in_button(driver):
  60. try:
  61. button = driver.find_element_by_link_text('签到')
  62. except NoSuchElementException:
  63. return False
  64. else:
  65. ActionChains(driver).move_to_element(button).click().perform()
  66. return True
  67. def sign_in(driver):
  68. while True:
  69. try:
  70. time.sleep(2)
  71. button = driver.find_element_by_id('emot_1')
  72. except NoSuchElementException:
  73. continue
  74. else:
  75. ActionChains(driver).move_to_element(button).click().perform()
  76. try:
  77. time.sleep(2)
  78. submit = driver.find_element_by_name('signpn')
  79. except NoSuchElementException:
  80. continue
  81. else:
  82. ActionChains(driver).move_to_element(submit).click().perform()
  83. break
  84. def get_image(driver):
  85. time.sleep(8)
  86. element = driver.find_element_by_class_name('geetest_widget')
  87. vc_image = get_vc_image(element)
  88. return vc_image