SignIn.py 2.1 KB

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