SignIn.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. time.sleep(2)
  69. button = driver.find_element_by_id('emot_1')
  70. ActionChains(driver).move_to_element(button).click().perform()
  71. time.sleep(2)
  72. submit = driver.find_element_by_name('signpn')
  73. ActionChains(driver).move_to_element(submit).click().perform()
  74. def get_image(driver):
  75. time.sleep(8)
  76. element = driver.find_element_by_class_name('geetest_widget')
  77. vc_image = get_vc_image(element)
  78. return vc_image