1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| import requests from lxml import etree
login_url = 'http://sso.cczu.edu.cn/sso/login?service=http%3A%2F%2Fs.cczu.edu.cn%2F' home_url = 'http://219.230.159.132/web_cas/web_cas_login_jwgl.aspx' grade_url = 'http://219.230.159.132/web_cjgl/cx_cj_xh.aspx' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66 ' } session = requests.session() login_page_data = etree.HTML(session.get(url=login_url, headers=headers).content.decode()) execution = login_page_data.xpath('//input[@name="execution"]/@value')[0] lt = login_page_data.xpath('//input[@name="lt"]/@value')[0] data = { 'username': '学号', 'password': '密码', 'lt': lt, 'execution': execution, '_eventId': 'submit', 'useVCode': 'false' } session.post(url=login_url, data=data, headers=headers) session.get(url=home_url, headers=headers) grade_page = session.get(url=grade_url, headers=headers).content.decode() grade_data = etree.HTML(grade_page) trs = grade_data.xpath('//table[@id="gvcj1"]/tr[@class="dg1-item"]') for tr in trs: s_id = tr.xpath('./td[1]/text()')[0] s_name = tr.xpath('./td[2]/text()')[0] s_term = tr.xpath('./td[3]/text()')[0] s_subject = tr.xpath('./td[4]/text()')[0] s_type = tr.xpath('./td[5]/text()')[0] s_grade = tr.xpath('./td[6]/text()')[0] s_properties = tr.xpath('./td[7]/text()')[0] s_point = tr.xpath('./td[8]/text()')[0] s_time = tr.xpath('./td[9]/text()')[0] s_code = tr.xpath('./td[10]/text()')[0] s_hour = tr.xpath('./td[11]/text()')[0] print(' 学号:' + s_id + '\n', '姓名:' + s_name + '\n', '学期:' + s_term + '\n', '科目:' + s_subject + '\n', '类别:' + s_type + '\n', '学分:' + s_grade + '\n', '分数:' + s_properties + '\n', '性质:' + s_point + '\n', '绩点:' + s_time + '\n', '课程代码:' + s_code + '\n', '课时:' + s_hour + '\n')
|