Skip to content

Commit

Permalink
选课网更新,验证码无法获取已解决
Browse files Browse the repository at this point in the history
  • Loading branch information
zghyy committed Dec 25, 2020
1 parent 503cb70 commit db9371b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
31 changes: 20 additions & 11 deletions LOGIN.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ class ZUCC:
CheckCodeURL = "http://xk.zucc.edu.cn"
CheckCodeHeader = ""
PlanCourageURL = "http://xk.zucc.edu.cn/xsxk.aspx"
xsmain="http://xk.zucc.edu.cn/xs_main.aspx"
xsmain = "http://xk.zucc.edu.cn/xs_main.aspx?xh="
GetCodeKeyURL = "http://xk.zucc.edu.cn/ajaxRequest/Handler1.ashx"


# Account为登录用的账户
class Account:
def __init__(self, name=None, password=None):
self.session = requests.Session()
self.soup = None
self.POSTDate = {'__LASTFOCUS': "", '__VIEWSTATE': "随机码", '__VIEWSTATEGENERATOR': "9BD98A7D",
'__EVENTTARGET': "", '__EVENTARGUMENT': "", 'txtUserName': "", 'TextBox2': "",
'txtSecretCode': "-1", 'RadioButtonList1': "%E5%AD%A6%E7%94%9F",
'Button1': "%E7%99%BB%E5%BD%95"}
'txtSecretCode': "-1", 'RadioButtonList1': "学生",
'Button1': "登录"}
self.account_data = RW_ACCOUNT.read_account()
if name == None and password == None:
self.POSTDate["txtUserName"] = self.account_data["username"]
Expand All @@ -38,9 +39,15 @@ def __init__(self, name=None, password=None):

def __refresh_code(self):
# 获取验证码
postdata = {"FunMode": "GETYZM"}
res = self.session.post(url=ZUCC.GetCodeKeyURL, data=postdata, headers=ZUCC.InitHeader)
image_response = self.session.get(ZUCC.CheckCodeURL+res.text, stream=True)
# self.POSTDate["button2"] = "刷新验证码"
# res = self.session.post(url=ZUCC.CheckCodeURL, data=self.POSTDate, headers=ZUCC.InitHeader)
# imgsoup = BeautifulSoup(res.text, 'lxml')
imgs = self.soup.find_all("img")
useimg = ""
for img in imgs:
if img.get("id") == "icode":
useimg = img.get("src")
image_response = self.session.get(ZUCC.CheckCodeURL + useimg, stream=True)

image = image_response.content
try:
Expand All @@ -63,6 +70,7 @@ def __get_check_code_ocr(self):
img_dir = self.__refresh_code()
print("###Identify checkCode")
self.POSTDate['txtSecretCode'] = OCR_CODE.run(img_dir, dir_now=img_dir)
# print(self.POSTDate['txtSecretCode'])

# 登录进入主页
def login(self):
Expand All @@ -73,15 +81,16 @@ def login(self):
if init_response.ok:
print("##GET login page succeed!")
break
login_soup = BeautifulSoup(init_response.text, "lxml")
self.POSTDate["__VIEWSTATE"] = login_soup.find('input', attrs={'name': '__VIEWSTATE'})["value"]
self.soup = BeautifulSoup(init_response.text, "lxml")
self.POSTDate["__VIEWSTATE"] = self.soup.find('input', attrs={'name': '__VIEWSTATE'})["value"]
# print("###GET StateCode:", self.POSTDate["__VIEWSTATE"]) # 随机码
# print("###GET checkCode")
self.__get_check_code_ocr()
print("##POST login")
try_time = 0
login_response = self.session.post(ZUCC.MainURL, data=self.POSTDate,headers=ZUCC.InitHeader)
while try_time < 300:
login_response = self.session.post(ZUCC.MainURL, data=self.POSTDate)
login_response = self.session.get(ZUCC.xsmain + self.account_data["username"], headers=ZUCC.InitHeader)
# 进入主页
self.soup = BeautifulSoup(login_response.text, "lxml")
if login_response.ok and self.soup.find("title").text == "正方教务管理系统":
Expand All @@ -97,5 +106,5 @@ def login(self):


if __name__ == '__main__':
account =Account()
account.login()
account = Account()
account.login()
2 changes: 1 addition & 1 deletion OCR_CODE.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ def run(image_path, dir_now):


if __name__ == "__main__":
print(run())
print(run(os.getcwd() + "/",os.getcwd() + "/"))
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@

之前修改计划内选课的时候顺便写的一个文档,从最开始的页面分析GET到抢课界面,到最后发送POST数据包进行抢课

`tel:13588362431`
`vx:13588362431`

0 comments on commit db9371b

Please sign in to comment.