#_*_coding:utf-8_*_ fromSeleniumImportWebdriver fromSelenium.webdriver.common.action_chainsImportActionchainsImportOs,urllib.request,sys,importlib,time,winreg
deflogin_in (Username,password):#Educational Administration System websitePostURL ="" #Verification Code URLSecretcodeurl ="" #Get the desktop path address via the win registryKey =winreg. Openkey (winreg. HKEY_CURRENT_USER, R'Software\microsoft\windows\currentversion\explorer\shell Folders',) CWD= WinReg. QueryValueEx (Key,"Desktop") [0] address= str (CWD) +"/image.jpg"driver.get (PostURL) driver.find_element_by_name ("txtUserName"). Send_keys (username)#Dual Input correlationDriver.find_element_by_name ('Textbox1'). Click () driver.find_element_by_id ('TextBox2'). Send_keys (password)#Verification Code #read Verification code URL, open Local path, write, enter verification codeDownPicture =Urllib.request.urlopen (Secretcodeurl). Read () Local= Open (Address,'WB') Local.write (downpicture) local.close ()Print(U"please look for your verification code from the desktop") Print(U"Please enter the verification code:") Secretcode=input () driver.find_element_by_id ('Txtsecretcode'). Send_keys (Secretcode) Driver.find_element_by_xpath ("//*[@id = ' Button1 ')"). Click ()defTo_grab_class (corm,username): Directurl="http://127.0.0.1/(mil3m1jzac4e0a55aqz5ky45)/xs_main.aspx?xh="+username Driver.get (directurl)#Mouse HoverChain =Actionchains (Driver) Implement= Driver.find_element_by_link_text (U"Online Course Selection") chain.move_to_element (implement). Perform ()ifCorm = = 1: Driver.find_element_by_link_text ("School Elective"). Click ()Else: Driver.find_element_by_link_text ("Elective courses for faculties and departments"). Click ()defCheck_all (): Checkboxs= Driver.find_elements_by_xpath ("//input[@type = ' checkbox ']") I=1 forClickinchcheckboxs:i=i+1ifI% 2 = =0:click.click () driver.find_element_by_id ("Button1"). Click ()if __name__=="__main__": Importlib.reload (SYS)Print(U"Please enter the number of the study:") Username=input ()Print(U"Please enter your password:") Password=input ()Print(U"for elective courses, please press 1, please press 2 for elective courses of faculties:") Corm=int (input ())#the Phentomjs browser used here needs to be changed by itselfDriver = Webdriver. PHANTOMJS (executable_path=r"D:\Grab_class\phantomjswindows\bin\phantomjs.exe") login_in (Username,password) to_grab_class (corm,username) check_all ()
Python Selenium + PHENTOMJS simulation landing educational Management system "grab class"