├── .gitignore ├── .idea ├── .gitignore ├── vcs.xml ├── inspectionProfiles │ └── Project_Default.xml ├── modules.xml ├── libraries │ ├── Maven__junit_junit_3_8_1.xml │ ├── Maven__org_jsoup_jsoup_1_11_3.xml │ └── Maven__com_alibaba_fastjson_1_2_47.xml ├── misc.xml ├── compiler.xml └── collegeCourse.iml ├── .settings └── org.eclipse.m2e.core.prefs ├── .project ├── src ├── main │ └── java │ │ └── online │ │ └── coursehelper │ │ └── collegeCoursecollegeCourse │ │ ├── App.java │ │ ├── QU.java │ │ └── SHU.java └── test │ └── java │ └── online │ └── coursehelper │ └── collegeCoursecollegeCourse │ └── AppTest.java ├── pom.xml └── Python ├── QU.py └── SHU.py /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__junit_junit_3_8_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_jsoup_jsoup_1_11_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | collegeCourse 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_alibaba_fastjson_1_2_47.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/java/online/coursehelper/collegeCoursecollegeCourse/App.java: -------------------------------------------------------------------------------- 1 | package online.coursehelper.collegeCoursecollegeCourse; 2 | import com.alibaba.fastjson.JSONObject; 3 | 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | public class App { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | System.out.println("请输入你的学号:"); 12 | String name = sc.nextLine(); 13 | System.out.println("请输入你的密码:"); 14 | String psd = sc.nextLine(); 15 | // 上海大学 16 | List res = SHU.getCourse(name, psd); 17 | 18 | //青岛大学 19 | // QU.getCourse(name, psd); 20 | System.out.println(res); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/online/coursehelper/collegeCoursecollegeCourse/AppTest.java: -------------------------------------------------------------------------------- 1 | package online.coursehelper.collegeCoursecollegeCourse; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /.idea/collegeCourse.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | online.coursehelper.collegeCoursecollegeCourse 5 | collegeCourse 6 | jar 7 | 1.0-SNAPSHOT 8 | collegeCourse 9 | http://maven.apache.org 10 | 11 | 12 | junit 13 | junit 14 | 3.8.1 15 | test 16 | 17 | 18 | 19 | org.jsoup 20 | jsoup 21 | 1.11.3 22 | 23 | 24 | com.alibaba 25 | fastjson 26 | 1.2.47 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/online/coursehelper/collegeCoursecollegeCourse/QU.java: -------------------------------------------------------------------------------- 1 | package online.coursehelper.collegeCoursecollegeCourse; 2 | 3 | import org.jsoup.Connection; 4 | import org.jsoup.Jsoup; 5 | 6 | import javax.imageio.ImageIO; 7 | import javax.swing.*; 8 | import java.io.ByteArrayInputStream; 9 | 10 | public class QU { 11 | public static void getCourse(String number, String psd) { 12 | try { 13 | System.out.println("正在登录....."); 14 | Connection.Response connect = Jsoup.connect("http://jw.qdu.edu.cn/academic/student/currcourse/currcourse.jsdo?year=39&term=2").execute(); 15 | System.out.println(connect.cookies()); 16 | Connection.Response verification_code = Jsoup.connect("http://jw.qdu.edu.cn/academic/getCaptcha.do?0.3851235093964869") 17 | .cookies(connect.cookies()) 18 | .ignoreContentType(true) 19 | .execute(); 20 | ImageIcon image = new ImageIcon(ImageIO.read(new ByteArrayInputStream(verification_code.bodyAsBytes()))); 21 | JOptionPane.showMessageDialog(null, image, "Captcha image", JOptionPane.PLAIN_MESSAGE); 22 | } catch (Exception e) { 23 | e.printStackTrace(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Python/QU.py: -------------------------------------------------------------------------------- 1 | ''' 2 | author: Jacob 3 | describe: 获取青岛大学学生最新课表 4 | ''' 5 | 6 | from io import BytesIO 7 | from pytesseract import image_to_string 8 | import requests 9 | from PIL import Image 10 | import time 11 | 12 | 13 | def get_course_table(): 14 | stdid = input('请输入学号: ') 15 | password = input('请输入密码: ') 16 | if stdid and password: 17 | Login_Data = {'j_username': stdid, 18 | 'j_password': password} 19 | s = requests.session() 20 | login(s, Login_Data) 21 | 22 | 23 | def login(s, Login_Data): 24 | print('正在登陆') 25 | url_login = 'http://jw.qdu.edu.cn/academic/student/currcourse/currcourse.jsdo?year=39&term=2' 26 | code_url = 'http://jw.qdu.edu.cn/academic/getCaptcha.do?0.3851235093964869' 27 | s.get(url_login).content.decode("utf8", "ignore") 28 | res = s.get(code_url) 29 | byte_stream = BytesIO(res.content) 30 | verification_code = get_verification_code(byte_stream) 31 | is_right_code = s.post( 32 | "http://jw.qdu.edu.cn/academic/checkCaptcha.do?captchaCode=" + verification_code).content.decode('utf8') 33 | while is_right_code != 'true': 34 | print(is_right_code) 35 | print("验证码错误,正在重试") 36 | time.sleep(1) 37 | res = s.get(code_url) 38 | byte_stream = BytesIO(res.content) 39 | verification_code = get_verification_code(byte_stream) 40 | is_right_code = s.post( 41 | "http://jw.qdu.edu.cn/academic/checkCaptcha.do?captchaCode=" + verification_code).content.decode('utf8') 42 | a = s.post( 43 | "http://jw.qdu.edu.cn/academic/j_acegi_security_check?j_username=" + Login_Data['j_username'] + "&j_password=" + 44 | Login_Data['j_password'] + "&j_captcha=" + verification_code) 45 | print(a.content.decode('utf8', 'ignore')) 46 | 47 | 48 | def get_verification_code(byte_stream): 49 | image = Image.open(byte_stream) 50 | res = image_to_string(image) 51 | return res.replace(" ", "") 52 | 53 | 54 | get_course_table() 55 | -------------------------------------------------------------------------------- /Python/SHU.py: -------------------------------------------------------------------------------- 1 | ''' 2 | author: Jacob 3 | describe: 获取上海大学学生最新课表 4 | ''' 5 | 6 | import json 7 | 8 | import requests 9 | from bs4 import BeautifulSoup 10 | 11 | 12 | def get_course_table(): 13 | stdid = input('请输入学号: ') 14 | password = input('请输入密码: ') 15 | if stdid and password: 16 | Login_Data = {'j_username': stdid, 17 | 'j_password': password} 18 | s = requests.session() 19 | login(s, Login_Data) 20 | 21 | 22 | def login(s, Login_Data): 23 | # POST 登陆 24 | print('正在登陆') 25 | url_login = 'http://xk.autoisp.shu.edu.cn:8080' 26 | a = s.get(url_login).content.decode() 27 | # 登录界面 28 | # print(a) 29 | # print("===================================================") 30 | soup = BeautifulSoup(a, 'lxml') 31 | url_sso = soup.body.form['action'] 32 | data = {} 33 | for input_tag in soup.body.form.find_all('input'): 34 | data[input_tag['name']] = input_tag['value'] 35 | b = s.post(url_sso, data) 36 | c = s.post(b.url, Login_Data) 37 | soup1 = BeautifulSoup(c.content, 'lxml') 38 | data = {} 39 | for input_tag in soup1.body.form.find_all('input'): 40 | if input_tag.get('name', False): 41 | data[input_tag['name']] = input_tag['value'] 42 | s.post(soup1.body.form['action'], data) 43 | print('登录成功') 44 | print('正在获取课表....') 45 | # =======login-finished======== 46 | url_course_info = "http://cj.shu.edu.cn/StudentPortal/StudentSchedule" 47 | url_course_table = "http://cj.shu.edu.cn/StudentPortal/CtrlStudentSchedule" 48 | course_info = s.get(url_course_info) # 不知道为什么要访问两次,反正访问就对了 49 | course_info = s.get(url_course_info) # 打开教务管理系统点击查看课程信息 50 | soup_info = BeautifulSoup(course_info.content, "lxml") 51 | term = soup_info.find_all('option') 52 | academicTermID = term[-1]['value'] # 获取最新的学期 53 | # 真正拿到课表 54 | e = s.post(url_course_table, {'academicTermID': academicTermID}) # 获取最新的课表儿 55 | # 课表界面 56 | # print(e.content.decode()) 57 | soup2 = BeautifulSoup(e.content, "lxml") 58 | class_list = [] 59 | for idx, tr in enumerate(soup2.find_all('tr')): 60 | classdetail = {} 61 | if idx != 0 and idx != 1 and idx % 2 != 1: 62 | tds = tr.find_all('td') 63 | classdetail['courseId'] = str(tds[0].contents[0]).replace('\n', "").replace('\r', "").replace(' ', "") 64 | classdetail['name'] = str(tds[1].contents[0]).replace('\n', "").replace('\r', "").replace(' ', "") 65 | classdetail['teacherId'] = str(tds[2].contents[0]).replace('\n', "").replace('\r', "").replace(' ', "") 66 | classdetail['teacher'] = str(tds[3].contents[0]).replace('\n', "").replace('\r', "").replace(' ', "") 67 | classdetail['time'] = str(tds[4].contents[0]).replace('\n', "").replace('\r', "").replace(' ', "") 68 | classdetail['classroom'] = str(tds[5].contents[0]).replace('\n', "").replace('\r', "").replace(' ', "") 69 | classdetail['questionTime'] = str(tds[6].contents[0]).replace('\n', "").replace('\r', "").replace(' ', "") 70 | classdetail['questionRoom'] = str(tds[7].contents[0]).replace('\n', "").replace('\r', "").replace(' ', "") 71 | class_list.append(classdetail) 72 | if '课程编号' in e.content.decode(): 73 | print('获取课表成功') 74 | else: 75 | print('连接出错了呢,大概是账号密码有问题哦') 76 | return False 77 | print(class_list) 78 | return class_list 79 | 80 | get_course_table() 81 | -------------------------------------------------------------------------------- /src/main/java/online/coursehelper/collegeCoursecollegeCourse/SHU.java: -------------------------------------------------------------------------------- 1 | package online.coursehelper.collegeCoursecollegeCourse; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import org.jsoup.Connection; 5 | import org.jsoup.Jsoup; 6 | import org.jsoup.nodes.Document; 7 | import org.jsoup.nodes.Element; 8 | import org.jsoup.select.Elements; 9 | 10 | import java.util.ArrayList; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | /** 16 | * @author Jacob 17 | * @Deprecated 自动获取上海大学课表 18 | * @param {String} 学号 19 | * @param {String} 密码 20 | * @return List 21 | */ 22 | public class SHU { 23 | public static List getCourse(String number, String psd) { 24 | List course = new ArrayList<>(); 25 | try { 26 | Document doc; 27 | System.out.println("正在登录....."); 28 | Connection.Response connect = Jsoup.connect("https://oauth.shu.edu.cn/oauth/authorize?response_type=code&client_id=yRQLJfUsx326fSeKNUCtooKw&redirect_uri=http://cj.shu.edu.cn/passport/return&state=").execute(); 29 | 30 | Map user_password = new HashMap(); 31 | user_password.put("username", number); 32 | user_password.put("password", psd); 33 | user_password.put("login_submit", "登录/Login"); 34 | 35 | Connection.Response connect1 = Jsoup.connect("https://oauth.shu.edu.cn/login") 36 | .data(user_password) 37 | .cookies(connect.cookies()).followRedirects(false) 38 | .method(Connection.Method.POST).timeout(10000).execute(); 39 | System.out.println(connect1.header("location")); 40 | Connection.Response connect2 = Jsoup.connect("https://oauth.shu.edu.cn/oauth/authorize") 41 | .cookies(connect.cookies()).followRedirects(false) 42 | .method(Connection.Method.GET).timeout(10000).execute(); 43 | Connection.Response connect3 = Jsoup.connect(connect2.header("location")) 44 | .cookies(connect.cookies()).followRedirects(false) 45 | .method(Connection.Method.GET).timeout(10000).execute(); 46 | System.out.println("登录成功!"); 47 | System.out.println("正在获取课表....."); 48 | doc = Jsoup.connect("http://cj.shu.edu.cn/StudentPortal/StudentSchedule") 49 | .data("studentNo", number) 50 | .cookies(connect3.cookies()) 51 | .post(); 52 | Elements term = doc.body().select("option"); 53 | String academicTermID = term.last().attr("value"); 54 | Element coursePage = Jsoup.connect("http://cj.shu.edu.cn/StudentPortal/CtrlStudentSchedule") 55 | .data("academicTermID", academicTermID) 56 | .cookies(connect3.cookies()) 57 | .post() 58 | .body(); 59 | Elements ele2 = coursePage.select("tr"); 60 | for (int i = 2; i < ele2.size(); i++) { 61 | JSONObject courseItem = new JSONObject(); 62 | Elements items = ele2.get(i).getElementsByTag("td"); 63 | if(items.size() < 8){ 64 | continue; 65 | } 66 | courseItem.put("课程编号", items.get(0).text()); 67 | courseItem.put("课程名称", items.get(1).text()); 68 | courseItem.put("教师号", items.get(2).text()); 69 | courseItem.put("教师姓名", items.get(3).text()); 70 | courseItem.put("上课时间", items.get(4).text()); 71 | courseItem.put("上课教室", items.get(5).text()); 72 | courseItem.put("答疑时间", items.get(6).text()); 73 | courseItem.put("答疑地点", items.get(7).text()); 74 | course.add(courseItem); 75 | courseItem = new JSONObject(); 76 | } 77 | System.out.println("获取成功!"); 78 | } catch (Exception e) { 79 | e.printStackTrace(); 80 | } 81 | return course; 82 | } 83 | } 84 | --------------------------------------------------------------------------------