模拟登陆江西理工大学教务系统
Posted z-712
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了模拟登陆江西理工大学教务系统相关的知识,希望对你有一定的参考价值。
验证码这块,没有进行处理,暂时可视化输出显示,手动输入
1 # -*- coding:utf-8 -*- 2 # author:zxy 3 # date:2018-12-24 4 # update:2018-12-26 5 6 #https://cuiqingcai.com 7 import requests 8 import selenium 9 from selenium import webdriver 10 from time import sleep 11 from selenium.webdriver.support.ui import WebDriverWait 12 from selenium.webdriver.support import expected_conditions as EC 13 from selenium.webdriver.common.by import By 14 from bs4 import BeautifulSoup as bs 15 from bs4 import BeautifulSoup 16 from PIL import Image 17 18 def getCookie(url): 19 r=requests.get(url) 20 cookie=r.cookies 21 soup=BeautifulSoup(r.text,"lxml") 22 # print(r.text) 23 viewstate=soup.find(‘input‘)[‘value‘] 24 print(viewstate) 25 26 return cookie,viewstate 27 28 def getCheckCode(url,headers,cookies): 29 r=requests.get(url,headers=headers,cookies=cookies) 30 with open(‘code.jpg‘,‘wb‘) as f: 31 f.write(r.content) 32 im=Image.open(‘code.jpg‘) 33 im.show() 34 code=input("请输入验证码") 35 return code 36 37 def login(url,code,viewstate,headers,cookies): 38 formData={ 39 ‘__VIEWSTATE‘: viewstate, 40 ‘txtUserName‘: ‘201*****‘, 41 ‘TextBox2‘: ‘************‘, 42 ‘txtSecretCode‘: code, 43 ‘RadioButtonList1‘: ‘学生‘.encode(‘gb2312‘), 44 ‘Button1‘: ‘‘, 45 ‘lbLanguage‘: ‘‘, 46 ‘hidPdrs‘: ‘‘, 47 ‘hidsc‘: ‘‘ 48 } 49 r=requests.post(url,data=formData,headers=headers,cookies=cookies) 50 r.encoding=‘gb2312‘ 51 soup=BeautifulSoup(r.text,‘lxml‘) 52 welStr=soup.find(id=‘Label3‘).get_text() 53 name=soup.find(id=‘xhxm‘).get_text() 54 print(welStr,name) 55 56 def main(): 57 headers = { 58 ‘User-Agent‘: "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chr" 59 "ome/67.0.3396.99 Safari/537.36" 60 } 61 62 url = "http://ojw.jxust.edu.cn/" 63 cookies,viewstate=getCookie(url) 64 codeUrl = "http://ojw.jxust.edu.cn/CheckCode.aspx" 65 loginUrl="http://ojw.jxust.edu.cn/default2.aspx" 66 code=getCheckCode(codeUrl,headers,cookies) 67 68 login(loginUrl,code,viewstate,headers,cookies) 69 70 71 72 if __name__ == ‘__main__‘: 73 main()
以上是关于模拟登陆江西理工大学教务系统的主要内容,如果未能解决你的问题,请参考以下文章
python selenium + phentomjs 模拟登陆教务管理系统 “抢课”
python requests模拟登陆正方教务管理系统,并爬取成绩