app/src/main/java/com/hugo/myqlu/utils/ParseCourses.java
public class ParseCourses {

    private static List<CourseBean> courseList = new ArrayList<>();

    public static List<CourseBean> getKB(String response) {
        response = response.replace("<br>", "hu");
        Document document = Jsoup.parse(response);
        Element table1 = document.getElementById("Table1");
        //拿到tbody
        Element tbody = table1.select("tbody").get(0);
        //去除前面两行 ，时间和早晨
        tbody.child(0).remove();
        tbody.child(0).remove();
        //去除上午，下午，晚上
        tbody.child(0).child(0).remove();
        tbody.child(4).child(0).remove();
        tbody.child(8).child(0).remove();
        //去除无用行之后，还剩余
        Elements trs = tbody.select("tr");
        int rowNum = trs.size();
        //用map储存数据
        for (int i = 0; i < rowNum; i++) {
            if (i % 2 == 0) {
                //拿到每一行
                Element tr = trs.get(i);
                //一共有多少列 -2 晚自习有三节课，手动去掉最后一行，即第十一节课
                int columnNum = tr.childNodeSize() - 2;
                for (int j = 1; j < columnNum - 1; j++) {
                    String timeDetail = null;
                    switch (i) {
                        case 0:
                            timeDetail = "8:30-10:10";
                            break;
                        case 2:
                            timeDetail = "10:20-12:00";
                            break;
                        case 4:
                            timeDetail = "13:20-15:10";
                            break;
                        case 6:
                            timeDetail = "15:20-17:00";
                            break;
                        case 8:
                            timeDetail = "18:30-20:40";
                    }

                    Element colum = tr.child(j);
                    if (colum.hasAttr("rowspan")) {
                        CourseBean course = new CourseBean();
                        String text = colum.text();
                        //基于java的web开发(JSP/Sevlet) 周三第5,6节{第1-16周} 尹红丽 1号公教楼602
                        String[] strings = text.split("hu");
                        String name = "";
                        try {
                            if (strings.length > 4) {
                                name = strings[0] + "-" + strings[1].substring(strings[1].indexOf("|") + 1, strings[1].indexOf("}"));
                                String name2 = strings[5] + "-" + strings[6].substring(strings[6].indexOf("|") + 1, strings[6].indexOf("}"));
                                name = name + "\n" + name2;
                            } else {
                                name = strings[0];
                                if (strings[1].contains("单周")) {
                                    name = name + " -单周";
                                } else if (strings[1].contains("双周")) {
                                    name = name + " -双周";
                                }
                            }
                        } catch (ArrayIndexOutOfBoundsException e) {
                            course.setCourseName("暂无");
                        }
                        course.setCourseName(name);
                        course.setCourseTime(String.valueOf(j));
                        course.setCourstTimeDetail(timeDetail);
                        /**
                         * 有的课程不规范，缺少信息，导致解析错误，程序崩溃
                         */
                        String teacher = "";
                        try {
                            teacher = strings[2];
                        } catch (ArrayIndexOutOfBoundsException e) {
                            teacher = "暂无";
                        }
                        String location = "";
                        try {
                            location = strings[3];
                        } catch (ArrayIndexOutOfBoundsException e) {
                            location = "暂无";
                        }
                        course.setCourseTeacher(teacher);
                        course.setCourseLocation(location);
                        courseList.add(course);
                    }
                }
            }
        }
        return courseList;
    }

}
app/src/main/java/com/hugo/myqlu/dao/ExamDao.java
public class ExamDao {
    private Context mContext;

    public ExamDao(Context mContext) {
        this.mContext = mContext;
    }

    public boolean add(String examname, String examtime, String examlocation) {
        ExamHelper helper = new ExamHelper(mContext, 1);
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("examname", examname);
        values.put("examtime", examtime);
        values.put("examlocation", examlocation);
        long kaosiinfo = db.insert("kaoshiinfo", null, values);
        return kaosiinfo != -1;
    }

    public boolean query(String name) {
        boolean flag = false;
        ExamHelper helper = new ExamHelper(mContext, 1);
        SQLiteDatabase db = helper.getReadableDatabase();
        Cursor cursor = db.query("kaoshiinfo", null, "examname=?", new String[]{name}, null, null, null, null);
        if (cursor.moveToNext()) {
            flag = true;
        }
        cursor.close();
        db.close();
        return flag;
    }


    public List<ExamBean> queryAll() {
        ExamHelper helper = new ExamHelper(mContext, 1);
        SQLiteDatabase db = helper.getReadableDatabase();
        Cursor cursor = db.query("kaoshiinfo", null, null, null, null, null, null);
        List<ExamBean> examList = new ArrayList<>();
        while (cursor.moveToNext()) {
            ExamBean examBean = new ExamBean();
            String examName = cursor.getString(1);
            String examtime = cursor.getString(2);
            String examlocation = cursor.getString(3);
            examBean.setExamName(examName);
            examBean.setExamTime(examtime);
            examBean.setExamLocation(examlocation);
            examList.add(examBean);
        }
        cursor.close();
        db.close();
        return examList;
    }

    public boolean update(String name, String time, String location) {
        ExamHelper helper = new ExamHelper(mContext, 1);
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("examtime", time);
        values.put("examlocation", location);
        int update = db.update("kaoshiinfo", values, "examname=?", new String[]{name});
        return update != 0;
    }

    public void deleteAll() {
        ExamHelper helper = new ExamHelper(mContext, 1);
        SQLiteDatabase db = helper.getWritableDatabase();
        db.delete("kaoshiinfo", null, null);
    }
}
app/src/main/java/com/hugo/myqlu/dao/BaseInfoDao.java
public class BaseInfoDao {
    private Context mContext;

    public BaseInfoDao(Context context) {
        mContext = context;
    }

    //添加url到数据库
    public boolean add(String key, String value) {
        BaseInfoHelper helper = new BaseInfoHelper(mContext);
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("key", key);
        values.put("value", value);
        long id = db.insert("baseinfo", null, values);
        return id != -1;
    }

    public String query(String key) {
        BaseInfoHelper helper = new BaseInfoHelper(mContext);
        SQLiteDatabase db = helper.getReadableDatabase();
        Cursor cursor = db.query("baseinfo", new String[]{"value"}, "key=?", new String[]{key}, null, null, null);
        String value = null;
        if (cursor.moveToNext()) {
            value = cursor.getString(0);
        }
        cursor.close();
        db.close();
        return value;
    }

    public Map<String, String> queryAll() {
        BaseInfoHelper helper = new BaseInfoHelper(mContext);
        SQLiteDatabase db = helper.getReadableDatabase();
        Cursor cursor = db.query("baseinfo", new String[]{"key", "value"}, null, null, null, null, null, null);
        Map<String, String> map = new HashMap<>();
        while (cursor.moveToNext()) {
            String key = cursor.getString(0);
            String value = cursor.getString(1);
            map.put(key, value);
        }
        cursor.close();
        db.close();
        return map;
    }

    public boolean delete(String key) {
        BaseInfoHelper helper = new BaseInfoHelper(mContext);
        SQLiteDatabase db = helper.getWritableDatabase();
        int delete = db.delete("baseinfo", "key=?", new String[]{key});
        return delete != 0;
    }

    public boolean deleteAll() {
        BaseInfoHelper helper = new BaseInfoHelper(mContext);
        SQLiteDatabase db = helper.getWritableDatabase();
        int delete = db.delete("baseinfo", null, null);
        return delete != 0;
    }

}
app/src/main/java/com/hugo/myqlu/dao/CourseDao.java
public class CourseDao {
    private Context mContext;
    private CourseBean course;

    public CourseDao(Context mContext) {
        this.mContext = mContext;
    }

    public boolean add(String name, String time, String timedetail, String teacher, String location) {
        CourseHelper helper = new CourseHelper(mContext, 1);
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("name", name);
        values.put("time", time);
        values.put("timedetail", timedetail);
        values.put("teacher", teacher);
        values.put("location", location);
        long id = db.insert("course", null, values);
        return id != -1;
    }

    public List<CourseBean> query(String time) {
        CourseHelper helper = new CourseHelper(mContext, 1);
        SQLiteDatabase db = helper.getReadableDatabase();
        Cursor cursor = db.query("course", null, "time=?", new String[]{time}, null, null, null);
        List<CourseBean> dayCoueseList = new ArrayList<>();
        while (cursor.moveToNext()) {
            CourseBean course = new CourseBean();
            course.setId(cursor.getInt(0));
            course.setCourseName(cursor.getString(1));
            course.setCourseTime(cursor.getString(2));
            course.setCourstTimeDetail(cursor.getString(3));
            course.setCourseTeacher(cursor.getString(4));
            course.setCourseLocation(cursor.getString(5));
            dayCoueseList.add(course);
        }
        cursor.close();
        db.close();
        return dayCoueseList;
    }

    public List<CourseBean> queryAll() {
        CourseHelper helper = new CourseHelper(mContext, 1);
        SQLiteDatabase db = helper.getReadableDatabase();
        Cursor cursor = db.query("course", null, null, null, null, null, "time asc");
        List<CourseBean> allCourseList = new ArrayList<>();
        while (cursor.moveToNext()) {
            CourseBean course = new CourseBean();
            course.setId(cursor.getInt(0));
            course.setCourseName(cursor.getString(1));
            course.setCourseTime(cursor.getString(2));
            course.setCourstTimeDetail(cursor.getString(3));
            course.setCourseTeacher(cursor.getString(4));
            course.setCourseLocation(cursor.getString(5));
            allCourseList.add(course);
        }
        cursor.close();
        db.close();
        return allCourseList;
    }

    public CourseBean queryById(String id) {
        CourseHelper helper = new CourseHelper(mContext, 1);
        SQLiteDatabase db = helper.getReadableDatabase();
        Cursor cursor = db.query("course", null, "_id=?", new String[]{id}, null, null, null);
        if (cursor.moveToNext()) {
            course = new CourseBean();
            course.setId(cursor.getInt(0));
            course.setCourseName(cursor.getString(1));
            course.setCourseTime(cursor.getString(2));
            course.setCourstTimeDetail(cursor.getString(3));
            course.setCourseTeacher(cursor.getString(4));
            course.setCourseLocation(cursor.getString(5));
        }
        cursor.close();
        db.close();
        return course;
    }

    public boolean update(String id, String name, String time, String timeDetail, String teacher, String location) {
        CourseHelper helper = new CourseHelper(mContext, 1);
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("name", name);
        values.put("time", time);
        values.put("timedetail", timeDetail);
        values.put("teacher", teacher);
        values.put("location", location);
        int course = db.update("course", values, "_id=?", new String[]{id});
        return course == 1;
    }

    public boolean deleteAll() {
        CourseHelper helper = new CourseHelper(mContext, 1);
        SQLiteDatabase db = helper.getWritableDatabase();
        int delete = db.delete("course", null, null);
        db.close();
        return delete != 0;
    }

    public boolean delete(String id) {
        CourseHelper helper = new CourseHelper(mContext, 1);
        SQLiteDatabase db = helper.getWritableDatabase();
        int delete = db.delete("course", "_id=?", new String[]{id});
        db.close();
        return delete != 0;
    }

}
app/src/main/java/com/hugo/myqlu/bean/ExamBean.java
public class ExamBean {
    private String examName;
    private String examLocation;
    private String examTime;


    public String getExamLocation() {
        return examLocation;
    }

    public void setExamLocation(String examLocation) {
        this.examLocation = examLocation;
    }

    public String getExamName() {
        return examName;
    }

    public void setExamName(String examName) {
        this.examName = examName;
    }

    public String getExamTime() {
        return examTime;
    }

    public void setExamTime(String examTime) {
        this.examTime = examTime;
    }

    @Override
    public String toString() {
        return "ExamBean{" +
                ", examName='" + examName + '\'' +
                ", examLocation='" + examLocation + '\'' +
                ", examTime='" + examTime + '\'' +
                '}';
    }
}
app/src/main/java/com/hugo/myqlu/utils/SpUtil.java
public class SpUtil {
    public static SharedPreferences getSp(Context context, String name) {
        return context.getSharedPreferences(name, Context.MODE_PRIVATE);
    }
}
app/src/main/java/com/hugo/myqlu/utils/ParseExam.java
public class ParseExam {
    public static List<ExamBean> parse(String response) {
        Document document = Jsoup.parse(response);
        Element table = document.getElementById("DataGrid1");
        Elements tbody = table.select("tbody");
        Elements trs = tbody.select("tr");
        trs.get(0).remove();
        List<ExamBean> ksList = new ArrayList<>();
        for (int i = 1; i < trs.size(); i++) {
            Element tr = trs.get(i);
            ExamBean examBean = new ExamBean();
            examBean.setExamName(tr.child(1).text());
            examBean.setExamTime(tr.child(3).text());
            examBean.setExamLocation(tr.child(4).text());
            ksList.add(examBean);
        }
        return ksList;
    }
}
app/src/main/java/com/hugo/myqlu/utils/HtmlUtils.java
public class HtmlUtils {
    private String response;

    public HtmlUtils(String response) {
        this.response = response;
    }


    public String getXhandName() {
        Document document = Jsoup.parse(response);
        Element xhxm = document.getElementById("xhxm");
        String text = xhxm.text();
        return text;
    }

    public List<ScoreBean> parseScore() {
        List<ScoreBean> scoreList = new ArrayList<>();
        Document document = Jsoup.parse(response);
        Element dataGrid1 = document.getElementById("DataGrid1");
        Elements trs = dataGrid1.select("tbody").select("tr");
        for (int i = 0; i < trs.size(); i++) {
            ScoreBean bean = new ScoreBean();
            Elements tds = trs.get(i).select("td");
            for (int j = 0; j < tds.size(); j++) {
                switch (j) {
                    case 0:
                        bean.setCourseId(tds.get(j).text());
                        break;
                    case 1:
                        bean.setCourseName(tds.get(j).text());
                        break;
                    case 2:
                        bean.setCourseXz(tds.get(j).text());
                        break;
                    case 3:
                        bean.setCourseCj(tds.get(j).text());
                        break;
                    case 4:
                        bean.setCourseGs(tds.get(j).text());
                        break;
                    case 5:
                        bean.setCourseBk(tds.get(j).text());
                        break;
                    case 6:
                        bean.setCourseCx(tds.get(j).text());
                        break;
                    case 7:
                        bean.setCourseXf(tds.get(j).text());
                        break;
                    case 8:
                        bean.setCourseBj(tds.get(j).text());
                        break;
                }
            }
            scoreList.add(bean);
        }
        return scoreList;
    }

    /**
     * 返回成绩查询页面的年份集合
     *
     * @return
     */
    public List<String> parseSelectYearList() {
        Document document = Jsoup.parse(response);
        Element select = document.getElementById("ddlXN");
        Elements options = select.select("option");
        List<String> tempList = new ArrayList<>();
        List<String> yearList = new ArrayList<>();
        for (Element option : options) {
            tempList.add(option.text());
        }
        for (int j = tempList.size() - 1; j > 0; j--) {
            yearList.add(tempList.get(j));
        }
        return yearList;
    }

}
app/src/main/java/com/hugo/myqlu/bean/CourseBean.java
public class CourseBean {
    private String courseName;
    private String courseTime;
    private String courstTimeDetail;
    private String courseTeacher;
    private String courseLocation;
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCourseLocation() {
        return courseLocation;
    }

    public void setCourseLocation(String courseLocation) {
        this.courseLocation = courseLocation;
    }

    public String getCourstTimeDetail() {
        return courstTimeDetail;
    }

    public void setCourstTimeDetail(String courstTimeDetail) {
        this.courstTimeDetail = courstTimeDetail;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public String getCourseTeacher() {
        return courseTeacher;
    }

    public void setCourseTeacher(String courseTeacher) {
        this.courseTeacher = courseTeacher;
    }

    public String getCourseTime() {
        return courseTime;
    }

    public void setCourseTime(String courseTime) {
        this.courseTime = courseTime;
    }

    @Override
    public String toString() {
        return getCourseName() + "-" + getCourseTime() + "-" + getCourstTimeDetail() + "-" + getCourseTeacher() + "-" + getCourseLocation();
    }
}
app/src/main/java/com/hugo/myqlu/utils/TextEncoderUtils.java
public class TextEncoderUtils {
    public static String encoding(String text) {
        try {
            text = URLEncoder.encode(text, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return text;
    }
}


Question: import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.hugo.myqlu.R;
import com.hugo.myqlu.bean.CourseBean;
import com.hugo.myqlu.bean.ExamBean;
import com.hugo.myqlu.dao.BaseInfoDao;
import com.hugo.myqlu.dao.CourseDao;
import com.hugo.myqlu.dao.ExamDao;
import com.hugo.myqlu.utils.HtmlUtils;
import com.hugo.myqlu.utils.ParseCourses;
import com.hugo.myqlu.utils.ParseExam;
import com.hugo.myqlu.utils.SpUtil;
import com.hugo.myqlu.utils.TextEncoderUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.PostFormBuilder;
import com.zhy.http.okhttp.callback.BitmapCallback;
import com.zhy.http.okhttp.callback.StringCallback;
import com.zhy.http.okhttp.request.RequestCall;
import java.io.IOException;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

                    @Override
                    public void onResponse(Bitmap response) {
                        //设置验证码
                        ivCodes.setImageBitmap(response);
                    }
                });
    }

    //登录前检查输入的数据
    private void attemptLogin() {
        View focusView = null;
        userId = etUsername.getText().toString().trim();
        password = etPassword.getText().toString().trim();
        code = etCode.getText().toString().trim();
        if (TextUtils.isEmpty(userId)) {
            etUsername.setError("学号不能为空");
            focusView = etUsername;
        } else if (TextUtils.isEmpty(password)) {
            etPassword.setError("密码不能为空");
            focusView = etPassword;
        } else if (TextUtils.isEmpty(code)) {
            etCode.setError("验证码不能为空");
            focusView = etCode;
        }
        if (focusView != null) {
            focusView.requestFocus();
        } else {
            //向服务器请求登录
            requestLogin();
        }
    }

    /**
     * 向服务器模拟登陆
     */
    private void requestLogin() {
        int visibility = tvError.getVisibility();
        if (visibility == View.VISIBLE) {
            tvError.setVisibility(View.INVISIBLE);
        }

        pbLogin.setVisibility(View.VISIBLE);
        final PostFormBuilder post = OkHttpUtils.post();
        post.url(loginUrl);
        post.tag(this);
        //下面数据抓包可以得到
        post.addParams("__VIEWSTATE", "dDwtMTMxNjk0NzYxNTs7PpK7CYMIAY8gja8M8G8YpGL8ZEAL");
        post.addParams("__VIEWSTATEGENERATOR", "92719903");
        post.addParams("txtUserName", userId);
        post.addParams("TextBox2", password);
        post.addParams("txtSecretCode", code);
        post.addParams("RadioButtonList1", "%D1%A7%C9%FA");
        post.addParams("Button1", "");
        post.addParams("lbLanguage", "");
        post.addHeader("Host", "210.44.159.4");
        post.addHeader("Referer", "//210.44.159.4/default2.aspx");
        post.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36");
        post.build()
                .connTimeOut(5000)
                .execute(new StringCallback() {

                    @Override
                    public void onError(Call call, Exception e) {
                        pbLogin.setVisibility(View.GONE);
                        tvError.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onResponse(String response) {
                        View focusView = null;
                        if (response.contains("验证码不正确")) {
                            etCode.setError("验证码错误");
                            focusView = etCode;
                        } else if (response.contains("密码错误")) {
                            etPassword.setError("密码错误");
                            focusView = etPassword;
                        } else if (response.contains("用户名不存在")) {
                            etUsername.setError("用户名不存在");
                            focusView = etUsername;
                        }
                        if (focusView != null) {
                            focusView.requestFocus();
                            pbLogin.setVisibility(View.INVISIBLE);
                            //切换验证码
                            changCodeImage();
                        } else {
                            //登录成功
                            pbLogin.setVisibility(View.INVISIBLE);
                            //初始化用户数据
//                            initURL(response);
                            showSaveDataDialog(response);
                        }
                    }
                });
    }

    private void showSaveDataDialog(String response) {

        waitDialog = new ProgressDialog(mContext);
        waitDialog.setTitle("请稍后");
        waitDialog.setMessage("Loading...");
        waitDialog.show();
        initURL(response);
        initCourseData();
    }

    /**
     * 初始化用户数据
     *
     * @param response
     */
    private void initURL(String response) {
        HtmlUtils utils = new HtmlUtils(response);
        String xhandName = utils.getXhandName();
        String[] split = xhandName.split(" ");
        //用户的学号
        stuXH = split[0];
        //用户的姓名
        stuName = split[1].replace("同学", "");
Answer:         stuNameEncoding = TextEncoderUtils.encoding(stuName);