def login(username, password, opener=my_opener): resp = http_tool.http_request_get(URL_BASE + 'index.jsp', opener) # soup = Soup(resp, BEAUTIFUL_SOUP_FEATURES) # print(soup) data = {'j_username': username, 'j_password': password, 'button1': '登 录'} resp = http_tool.http_request_post(URL_BASE + 'j_acegi_security_check', data, opener) soup = Soup(resp, BEAUTIFUL_SOUP_FEATURES) err = soup.select('#error') if len(err) > 0: raise Exception(err[0].string)
def obtain_teaching_evaluate_tasks(opener=my_opener): resp = http_tool.http_request_get(URL_BASE + 'stuMission.do', opener) soup = Soup(resp, BEAUTIFUL_SOUP_FEATURES) datatable = soup.select('#datatable')[1].tbody.contents[2::2] tasks = [] for data in datatable: a = data.contents[9].contents[1].a if a is None: continue task = urllib.parse.quote(a['href'], safe='?=&') tasks.append(task) return tasks
def teaching_evaluate(url, opener=my_opener): resp = http_tool.http_request_get(URL_BASE + url, opener) soup = Soup(resp, BEAUTIFUL_SOUP_FEATURES) inputs = soup.find_all(['input', 'textarea']) data = {} print(inputs) for i in inputs: if i.has_attr('type') and i['type'] == 'button': continue if i.name == 'textarea': i['value'] = '上课讲的很好' elif len(i['value']) == 0 and i['name'].startswith('itemid'): i['value'] = '95' data[i['name']] = i['value'] resp = http_tool.http_request_post(URL_BASE + 'eva/index/putresult.jsdo', data, opener)
def teaching_evaluate(url, opener=my_opener): url_params = urllib.parse.parse_qs(urllib.parse.urlsplit(url).query) resp = http_tool.http_request_get( URL_BASE + url, opener, {'Referer': 'http://210.36.49.12/dqzljk/stuMission.do'}) soup = Soup(resp, BEAUTIFUL_SOUP_FEATURES) token_str = soup.select('#tokenStr')[0]['value'] resp = http_tool.http_request_post(URL_BASE + 'getGread.do?', {'contentId': url_params['tcid'][0]}, opener, {'Referer': URL_BASE + url}) gread = json.loads( resp.decode("utf-8").split('p~p')[4].replace('\'', '\"'))[1:] mark_str = '' standard_id = '' for item in gread: standard_id += item['id'] + '~' mark_str += '5~' post_params = { 'tokenStr': token_str, 'skid': url_params['skid'][0], 'standardid': standard_id, 'markStr': mark_str, 'comment': '--------请在这里填写您的建议--------', 'totalMark': 100, 'gmodel': 1, 'courseid': url_params['courseid'][0], 'cname': url_params['cname'][0], 'teacherid': url_params['teacherid'][0], 'tname': url_params['tname'][0], 'ctid': url_params['contentid'][0], 'ctype': 1 } resp = http_tool.http_request_post(URL_BASE + 'stuPgAjax.do?', post_params, opener, {'Referer': URL_BASE + url})
def teaching_evaluate_list(opener=my_opener): resp = http_tool.http_request_get(URL_BASE + 'accessModule.do?moduleId=508&groupId=', opener) soup = Soup(resp, BEAUTIFUL_SOUP_FEATURES) infolist = soup.select('.infolist_common') return infolist