classSelect.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import requests
  2. import time
  3. import re
  4. from lxml import etree
  5. from SendMessage import send_message
  6. cookie2 = 'cookiesession1=678B2867VWXYZACFHJLNPRTVXZBDD68F; JSESSIONID=qxRvln9OcQvtB2tsyMZNFsaFPIezr2xrNOfd1XVwfL5foSuYGOEQ!-2081256861; BIGipServerpool-hub-wsxkxt=2919893514.22811.0000'
  7. cookie1 = 'cookiesession1=678B2867VWXYZACFHJLNPRTVXZBDD68F; JSESSIONID=X6Q3JYn4xVtAvSnRsMlxbiWuxUSXcQ-kDf2b4ytHmfHMpBX8EDyv!1902579802; BIGipServerpool-hub-wsxkxt=2987002378.22811.0000'
  8. cookie = 'cookiesession1=678B2867VWXYZACFHJLNPRTVXZBDD68F; JSESSIONID=xmo6YX8cwTge1snOno9v9iMoBZ2rOYfGMtwYu3ZFKOB8NdFYZ3Sq!1902579802; BIGipServerpool-hub-wsxkxt=2987002378.22811.0000'
  9. headers = {
  10. 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.54',
  11. 'cookie':cookie2,
  12. 'host':'wsxk.hust.edu.cn'
  13. }
  14. root = 'http://wsxk.hust.edu.cn/zxqcourse/index_zxq.jsp'
  15. classlist = 'http://wsxk.hust.edu.cn/zxqstudentcourse/courseorclassroom.action?markZB=a'
  16. class1 = 'http://wsxk.hust.edu.cn/zxqstudentcourse/zxqclassroom.action?kcbh=w903964&ggkdl=&markZB='
  17. def solve_text_rcode(img):
  18. image = Image.open(img)
  19. text = pytesseract.image_to_string(image)
  20. time.sleep(5)
  21. print(text)
  22. return text
  23. def main():
  24. driver = webdriver.Edge()
  25. wait = WebDriverWait(driver, 10)
  26. driver.get(root)
  27. time.sleep(1)
  28. landing_btn = driver.find_element_by_class_name("landing_btn_bg")
  29. landing_btn.click()
  30. wait.until(EC.presence_of_element_located((By.ID,"un")))
  31. username = driver.find_element_by_id("un")
  32. username.send_keys("U202214377")
  33. password = driver.find_element_by_id("pd")
  34. password.send_keys("Zym00741")
  35. rcode_img = driver.find_element_by_id("codeImage").screenshot('temp.png')
  36. # img_url = 'https://pass.hust.edu.cn/cas/code'
  37. # with open('temp.gif','wb') as f:
  38. # print(driver.get_cookie(driver.current_url))
  39. # img = requests.get('https://pass.hust.edu.cn/cas/code',headers=headers1).content
  40. # f.write(img)
  41. rcode = driver.find_element_by_id("code")
  42. rcode.send_keys(solve_text_rcode("temp.png"))
  43. time.sleep(5)
  44. login_btn = driver.find_element_by_class_name("login_box_landing_btn")
  45. login_btn.click()
  46. input("WAITING...")
  47. driver.close()
  48. if __name__ == "__main__":
  49. # main()
  50. while True:
  51. time.sleep(3)
  52. response = requests.get(class1, headers=headers)
  53. if response.status_code == 200:
  54. print("success!")
  55. # print(response.text)
  56. html = etree.HTML(response.text)
  57. lst = html.xpath('//table/tr[@class="tablelist"]/td/text()')
  58. # print(lst)
  59. num = lst[6]
  60. num = re.sub("\r", "", num)
  61. num = re.sub(" ", "", num)
  62. num = re.sub("\n", "", num)
  63. # print(num)
  64. if num == "40/40":
  65. print('已满')
  66. # send_message("private",2945340446,"已满!!!")
  67. else:
  68. print(num)
  69. print("有空缺!!!")
  70. send_message("private",2945340446,num + "有空缺!!!")
  71. break