Skip to content

Commit

Permalink
fix:修复教师评估bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GentleCP committed Nov 6, 2020
1 parent de4c70b commit 830e06c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# UCAS Helper
![python version](https://img.shields.io/badge/python-3.5%2B-blue)
![demo version](https://img.shields.io/badge/version-2.0.3-yellowgreen)
![demo version](https://img.shields.io/badge/version-2.0.4-brightgreen)
![license](https://img.shields.io/badge/license-GNU%20v3-yellowgreen)
```angular2
*********************************************************************************
Expand All @@ -10,7 +10,7 @@
** # # # ####### # # # # # # # # # **
** ### ### ## ## ### # # ### ##### # ### # # **
** copyright@GentleCP **
** version: 2.0.3 **
** version: 2.0.4 **
** github: https://github.com/GentleCP/UCASHelper **
** 1:course sources download **
** 2:wifi login **
Expand Down Expand Up @@ -79,6 +79,7 @@
![](img/1.7.0.png)

# 2. 更新日志
- [2.0.4] 修复评估教师失败的bug
- [2.0.3] 修复了部分课程因html解析不当导致的课程资源无法下载的情况,本次更新需要用到新的依赖包`lxml=4.5.2`
已安装老版本的请重新执行`pip install -r requirements.txt`
- [2.0.2] 修复了因课程网站选课系统添加头部检查导致的**课程评估,分数查询**功能的失效。
Expand Down
14 changes: 9 additions & 5 deletions core/assess.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _assess_courses(self, course_ids):
def _get_teacher_ids(self):
# 通过课程评估url得到教师评估url
teacher_assess_url = self._course_assess_url.replace('course','teacher')
res = self._S.get(teacher_assess_url)
res = self._S.get(teacher_assess_url, headers=self.headers)
bs4obj = BeautifulSoup(res.text, 'html.parser')
urls = [url.get('href') for url in bs4obj.find_all('a', {'class': 'btn'})]
teacher_ids = []
Expand All @@ -119,7 +119,7 @@ def __assess_teacher(self, teacher_id):
except requests.Timeout:
res = self._S.get(self._urls['base_evaluateTeacher_url']['https'] + teacher_id, headers=self.headers)

bs4obj = BeautifulSoup(res.text,'html.parser')
bs4obj = BeautifulSoup(res.text,'lxml')
radios = bs4obj.find_all('input', attrs={'type': 'radio'})
value = radios[0]['value'] # 默认全5星好评
data = {}
Expand All @@ -132,12 +132,16 @@ def __assess_teacher(self, teacher_id):
data[item_id] = asses_msg
data['subjectiveCheckbox'] = ''
data['subjectiveRadio'] = ''
post_action = bs4obj.find('form', {'id': 'regfrm'})
try:
post_url = self._urls['base_url']['http'] + post_action.get('action')
except requests.Timeout:
post_url = self._urls['base_url']['https'] + post_action.get('action')
try:
post_url = self._urls['base_url']['http'] + bs4obj.find('form', {'id': 'regfrm'},timeout=5).get('action')
res = self._S.post(post_url,data=data,headers = self.headers,timeout=5)
res = self._S.post(post_url, data=data, headers=self.headers, timeout=5)
except requests.Timeout:
post_url = self._urls['base_url']['https'] + bs4obj.find('form', {'id': 'regfrm'}).get('action')
res = self._S.post(post_url, data=data, headers=self.headers)

tmp = BeautifulSoup(res.text, 'html.parser')
try:
flag = tmp.find('label', attrs={'id': 'loginSuccess'})
Expand Down
6 changes: 3 additions & 3 deletions core/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def __init__(self, user_info, urls):

def __keep_session(self):
try:
res = self._S.get(url=self._urls['course_select_url']['http'],timeout=5)
res = self._S.get(url=self._urls['course_select_url']['http'], headers = self.headers, timeout=5)
except requests.Timeout:
res = self._S.get(url=self._urls['course_select_url']['https'])
res = self._S.get(url=self._urls['course_select_url']['https'], headers = self.headers)
course_select_url = re.search(r"window.location.href='(?P<course_select_url>.*?)'", res.text).groupdict().get(
"course_select_url")
self._S.get(course_select_url,headers=self.headers)
Expand All @@ -67,7 +67,7 @@ def login(self):
json_res = res.json()

if json_res["f"]:
self._S.get(res.json()["msg"])
self._S.get(res.json()["msg"], headers=self.headers)
self._logger.info("sep登录成功!")
self.__keep_session()

Expand Down
2 changes: 1 addition & 1 deletion core/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
** # # # ####### # # # # # # # # # **
** ### ### ## ## ### # # ### ##### # ### # # **
** copyright@GentleCP **
** version: 2.0.3 **
** version: 2.0.4 **
** github: https://github.com/GentleCP/UCASHelper **
** 1:course sources download **
** 2:wifi login **
Expand Down

0 comments on commit 830e06c

Please sign in to comment.