def doEva(item): '''进行评估''' url="http://202.207.247.44:8089/jxpgXsAction.do?oper=wjpg" cookie = util.load_cookie(filename) headers = { "Host":"202.207.247.44:8089", "X-Requested-With":"cn.darkal.networkdiagnosis", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Proxy-Connection": "keep-alive", 'Origin':'http://202.207.247.44:8089', "Referer": "http://202.207.247.44:8089/jxpgXsAction.do?oper=wjpg", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" } string="老师的课程讲解十分细致,认真负责!" data={ "wjbm":item['wjbm'], "bpr":item['bpr'], "pgnr":item['pgnr'], "0000000045":"10_1".encode('gbk'), "zgpj":string.encode('gbk'), } # data=urllib.parse.urlencode(data).encode('gbk') html=session.post(url=url,headers=headers,data=data,cookies=cookie) bsObj=BeautifulSoup(html.text,'lxml') res=bsObj.find_all('script') for item in res: newews=item.get_text() if "评估失败" in newews: print("评估失败") else: print("评估成功")
def getEvaList(filename): '''获取待评估列表''' todoList = [] cookie = util.load_cookie(filename) url="http://202.207.247.44:8089/jxpgXsAction.do?oper=listWj" headers = {"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "Referer": "http://202.207.247.44:8089/menu/s_main.jsp", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" } try: html = session.get(url=url, headers=headers, cookies=cookie) bsObj = BeautifulSoup(html.text, 'lxml') html2list=bsObj.find_all('img',{'title':'评估'}) count=1 for item in html2list: res=item.get('name').replace('#','').split('@') newdic={'wjbm': res[0], 'bpr': res[1], 'pgnr': res[5], 'oper': 'wjShow', 'wjmc': res[3], 'bprm': res[2], 'pgnrm': res[4], 'pageSize': '20', 'page': '1', 'currentPage': '1', 'pageNo': ''} count+=1 todoList.append(newdic) except: pass return todoList
def chengji_all(filename): '''全部及格成绩''' res = [] cookie = util.load_cookie(filename) url = "http://202.207.247.44:8089/gradeLnAllAction.do?type=ln&oper=qbinfo&lnxndm=2017-2018学年春(两学期)#qb_2017-2018学年春(两学期)" # url='http://202.207.247.44:8089/gradeLnAllAction.do?type=ln&oper=fainfo&fajhh=5585' session = requests.Session() headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "Referer": "http://jwc.tyut.edu.cn/", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" } s = session.get(url=url, headers=headers, cookies=cookie) if s.status_code == 200: #print("**********及格成绩**********") sob = BeautifulSoup(s.content, "lxml") list = sob.find_all("td", {"align": "center"}) value_list = [] for value in list: value_t = value.get_text().strip() if len(value_t) != 0: # print(value_t) value_list.append(value_t) cou = 0 value_list.reverse() #{"score":"88.0","attri":"专业选修","gp":"2","name":"物联网传输课程设计"} score = "" attri = "" gp = "" name = "" temp = {} for info in value_list: cou = cou + 1 if cou == 1: #成绩 temp['score'] = info.strip() if cou == 2: #属性 temp['attri'] = info.strip() if cou == 3: #学分 temp['gp'] = info.strip() if cou == 5: #名称 temp['name'] = info.strip() if cou == 7: cou = 0 res.append(temp) temp = {} else: print("登录失败请刷新重试") return res
def get_yzm(filename): #访问图片记录生成的cookie 如果成功登录 此cookie可以换取数据 url = "http://202.207.247.44:8089/validateCodeAction.do" util.save_cookie(filename, url) cookie = util.load_cookie(filename) response = requests.get(url=url, cookies=cookie) rand = filename #cookie=response.cookies image = Image.open(BytesIO(response.content)) im = image.convert('L') binaryImage = im.point(initTable(), '1') im1 = binaryImage.convert('L') im1.save(path + rand + ".jpg") content = ocr_api.get_text(path + rand + ".jpg") os.system("rm -rf " + path + rand + ".jpg") return content
def login(yhm, mm, filename): '''登录''' yzm = get_pic.get_yzm(filename) while yzm == "error": time.sleep(0.2) yzm = get_pic.get_yzm(filename) cookie = util.load_cookie(filename) url = 'http://202.207.247.44:8089/loginAction.do' params = {'zjh': yhm, 'mm': mm, 'v_yzm': yzm} session = requests.Session() headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "Referer": "http://jwc.tyut.edu.cn/", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" } s = session.post(url=url, data=params, headers=headers, cookies=cookie) sob = BeautifulSoup(s.content, 'lxml') info_list = sob.find_all("font", {"color": "#990000"}) mm_error = "您的密码不正确,请您重新输入!" yzm_error = "你输入的验证码错误,请您重新输入!" yhm_error = "你输入的证件号不存在,请您重新输入!" if_bit = 1 for info in info_list: if info.get_text() == mm_error: if_bit = 2 return str(mm_error) elif info.get_text() == yzm_error: if_bit = 0 else: if_bit = 2 return str(yhm_error) if if_bit == 1: return str(200) else: time.sleep(0.5) login(yhm, mm, filename)
def dosome(filename): url="http://202.207.247.44:8089/jxpgXsAction.do" cookie = util.load_cookie(filename) headers = { "Host":"202.207.247.44:8089", "X-Requested-With":"cn.darkal.networkdiagnosis", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Proxy-Connection": "keep-alive", 'Origin':'http://202.207.247.44:8089', "Referer": "http://202.207.247.44:8089/jxpgXsAction.do?oper=wjpg", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" } todoList = getEvaList(filename) for item in todoList: html = session.post(url=url, headers=headers, data=item, cookies=cookie) doEva(item)
def kebiao_now(filename): '''本学期课表''' res = [] cookie = util.load_cookie(filename) url = "http://202.207.247.44:8089/xkAction.do?actionType=6" session = requests.Session() headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "Referer": "http://jwc.tyut.edu.cn/", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" } s = session.get(url=url, headers=headers, cookies=cookie) text = s.text.replace(' \r', '-') text = text.replace('\r', '') #print(text) #bs4 来解析网页文本 sob = BeautifulSoup(text, "lxml") title = sob.find("title").get_text().strip() class_list = sob.find_all("tr", {"bgcolor": "#FFFFFF"}) class_list2 = sob.find_all("tr", {"class": "odd"}) #print(title) if title == "错误信息": return ("教务处课表查询失败") else: cou = 1 for item in class_list: if len(item) != 3: temp = {} content = item.get_text().strip() content = content.replace(' ', '') content = content.replace('午', '') content = content.replace('上', '') content = content.replace('下', '') content = content.replace('休', '') content = content.replace('晚', '') content = content.replace('\n', '') content = content.replace('--', '-|') content = content.split('-') temp['Monday'] = content[2] temp['Tuesday'] = content[3] temp['Wednesday'] = content[4] temp['Thursday'] = content[5] temp['Friday'] = content[6] temp['Saturday'] = content[7] temp['Sunday'] = content[8] res.append(temp) cou = cou + 1 for item in class_list2: text = item.get_text().strip() text = text.replace(' ', '') text = text.replace('\r', '') if "方案" in text: content = text.split() if len(content) > 10: temp = {} temp['id'] = content[2] temp['time'] = content[10] res.append(temp) return res