Discover Packages
github.com/eipi10ydz/ustccas
package
module
Version:
v0.0.0-...-c95a54e
Opens a new window with list of versions in this module.
Published: Jun 9, 2017
License: BSD-2-Clause
Opens a new window with license information.
Imports: 9
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
USTC-CAS Spider Helper
中文文档
Usage
Preparation
Example
If the website is https://passport.ustc.edu.cn/login?service=http%3A%2F%2Fmis.teach.ustc.edu.cn/casLogin.do
Use get client
function to get client authenticated by i.ustc.edu.cn
Use the client to make a Get
request to https://passport.ustc.edu.cn/login?service=http%3A%2F%2Fmis.teach.ustc.edu.cn/casLogin.do
client.Get("https://passport.ustc.edu.cn/login?service=http%3A%2F%2Fmis.teach.ustc.edu.cn/casLogin.do")
Now you can inquire about your grade using the code below.
client.Post("http://mis.teach.ustc.edu.cn/querycjxx.do", "", nil)
Example code
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"github.com/eipi10ydz/ustccas"
)
func main() {
var err error
var client *http.Client
var resp *http.Response
// Step 3
if client, err = ustccas.GetClientAllPara("your student No", "your password"); err != nil {
log.Fatal(err)
}
// Step 4
client.Get("https://passport.ustc.edu.cn/login?service=http%3A%2F%2Fmis.teach.ustc.edu.cn/casLogin.do")
resp, err = client.Post("http://mis.teach.ustc.edu.cn/querycjxx.do", "", nil)
var body []byte
if body, err = ioutil.ReadAll(resp.Body); err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
Expand ▾
Collapse ▴
Documentation
¶
Find token in the login html, which will be used in post data.
For token is a hidden input, and the first one,
so it's easy to get the token by finding first input tag in login html and get its' value.
found is used to mark whether the token is found.
Get environment variable with upper case only, if not exist, return error.
Othewise return result of the environment variable.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.