def getTable(self): ''' Post request for your timetable ''' post_url = "http://jwfw.fudan.edu.cn/eams/courseTableForStd!courseTable.action" post_form = { "ignoreHead": "1", "setting.kind": "std", "startWeek": "1", "semester.id": self.__session.cookies['semester.id'] } post_form.update(self.__query_form) resp = self.__session.post(post_url, data=post_form, headers=HEADER_LOGIN, cookies=self.__cookies, timeout=40, allow_redirects=False) if resp.status_code == 200: logger.info("SUCCESS: Fetch timetable.") else: logger.error("Error: Connection error.") saveHtml("Table", resp.text, resp.status_code) return resp
def login_redirect(self, response, index): ''' Handle redirect ''' logger.info("Redirect to %s" % response.url) url = response.url header = HEADER_LOGIN resp = self.__session.get(url, headers=header, cookies=self.__cookies) logger.info("Redirect_%d: %d" % (index, resp.status_code)) set_cookies = parseCookie(resp.headers['Set-Cookie']) self.__cookies.update(set_cookies) saveHtml('Redirct_%d' % index, resp.text, resp.status_code) return resp
def __init__(self, fdu_id, fdu_pw): self.__session = requests.Session() self.__cookies = None self.__fdu_id = fdu_id self.__fdu_pw = fdu_pw self.__form_login = {} self.__gen_header = {} self._needCaptcha() self._get_lt() time.sleep(2) resp_login = self.login() saveHtml('Login', resp_login.text, resp_login.status_code)
def fetchTablePage(self): ''' Get table page for ids Note: ids is for the following steps post. ''' header = HEADER_LOGIN get_url = "https://jwfw.fudan.edu.cn/eams/courseTableForStd.action" resp = self.__session.get( get_url, headers=header, cookies=self.__cookies) self._set_cookies(resp) if resp.status_code == 200: logger.info('Success: Get ids.') else: logger.error('Fail: Get ids.') self._get_ids(resp) saveHtml("TablePage", resp.text, resp.status_code)