Python Selenium + phantomJS 模拟登陆教务管理系统 “抢课”
生活随笔
收集整理的這篇文章主要介紹了
Python Selenium + phantomJS 模拟登陆教务管理系统 “抢课”
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
# _*_coding:utf-8_*_ from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import os,urllib.request,sys,importlib,time,winreg
def Login_in(username,password):#教務管理系統網址PostUrl = ""#驗證碼網址SecretCodeUrl = ""#通過win注冊表獲得桌面路徑地址key = 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)#雙input關聯driver.find_element_by_name('Textbox1').click()driver.find_element_by_id('TextBox2').send_keys(password)#驗證碼#讀取驗證碼網址、打開本地路徑、寫入、輸入驗證碼downpicture = urllib.request.urlopen(SecretCodeUrl).read()local = open(address, 'wb')local.write(downpicture)local.close()print(u"請從桌面尋找你的驗證碼")print (u"請輸入驗證碼:")SecretCode = input()driver.find_element_by_id('txtSecretCode').send_keys(SecretCode)driver.find_element_by_xpath("//*[@id='Button1']").click() def To_Grab_class(corm,username):directUrl = "http://127.0.0.1/(mil3m1jzac4e0a55aqz5ky45)/xs_main.aspx?xh="+ usernamedriver.get(directUrl)#鼠標懸停chain = ActionChains(driver)implement = driver.find_element_by_link_text(u"網上選課")chain.move_to_element(implement).perform()if corm == 1 :driver.find_element_by_link_text("校選修課").click()else :driver.find_element_by_link_text("院系選修課").click() def check_all():checkboxs = driver.find_elements_by_xpath("//input[@type='checkbox']")i=1for click in checkboxs :i=i+1if i % 2 == 0 :click.click()driver.find_element_by_id("Button1").click()if __name__ == "__main__":importlib.reload(sys)print(u"請輸入學號:")username =input()print(u"請輸入密碼:")password = input()print(u"校選修課請按1,院系選修課請按2 :")corm = int(input())#使用的 phentomjs瀏覽器 此地需要自行更改driver = webdriver.PhantomJS(executable_path=r"d:\Grab_class\phantomjswindows\bin\phantomjs.exe")Login_in(username,password)To_Grab_class(corm,username) check_all()
def Login_in(username,password):#教務管理系統網址PostUrl = ""#驗證碼網址SecretCodeUrl = ""#通過win注冊表獲得桌面路徑地址key = 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)#雙input關聯driver.find_element_by_name('Textbox1').click()driver.find_element_by_id('TextBox2').send_keys(password)#驗證碼#讀取驗證碼網址、打開本地路徑、寫入、輸入驗證碼downpicture = urllib.request.urlopen(SecretCodeUrl).read()local = open(address, 'wb')local.write(downpicture)local.close()print(u"請從桌面尋找你的驗證碼")print (u"請輸入驗證碼:")SecretCode = input()driver.find_element_by_id('txtSecretCode').send_keys(SecretCode)driver.find_element_by_xpath("//*[@id='Button1']").click() def To_Grab_class(corm,username):directUrl = "http://127.0.0.1/(mil3m1jzac4e0a55aqz5ky45)/xs_main.aspx?xh="+ usernamedriver.get(directUrl)#鼠標懸停chain = ActionChains(driver)implement = driver.find_element_by_link_text(u"網上選課")chain.move_to_element(implement).perform()if corm == 1 :driver.find_element_by_link_text("校選修課").click()else :driver.find_element_by_link_text("院系選修課").click() def check_all():checkboxs = driver.find_elements_by_xpath("//input[@type='checkbox']")i=1for click in checkboxs :i=i+1if i % 2 == 0 :click.click()driver.find_element_by_id("Button1").click()if __name__ == "__main__":importlib.reload(sys)print(u"請輸入學號:")username =input()print(u"請輸入密碼:")password = input()print(u"校選修課請按1,院系選修課請按2 :")corm = int(input())#使用的 phentomjs瀏覽器 此地需要自行更改driver = webdriver.PhantomJS(executable_path=r"d:\Grab_class\phantomjswindows\bin\phantomjs.exe")Login_in(username,password)To_Grab_class(corm,username) check_all()
?
轉載于:https://www.cnblogs.com/liuyunbuji/p/7895503.html
總結
以上是生活随笔為你收集整理的Python Selenium + phantomJS 模拟登陆教务管理系统 “抢课”的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bzoj 2002
- 下一篇: JQuery 实现 锚点跳转