ustccas

package module
v0.0.0-...-c95a54e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2017 License: BSD-2-Clause Imports: 9 Imported by: 0

README

USTC-CAS Spider Helper

中文文档

Usage

  • Preparation
    • Install
      go get github.com/eipi10ydz/ustccas
      
    • Get website needed from http://i.ustc.edu.cn/
    • Use get client function to get client authenticated by i.ustc.edu.cn
    • Use the client to make a Get request to the website gotten in step 2
  • 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))
      }
      

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindToken

func FindToken(node *html.Node, found *bool) string

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.

func GetClient

func GetClient(username string) (client *http.Client, err error)

func GetClientAllPara

func GetClientAllPara(username string, password string) (client *http.Client, err error)

func GetEnvWrapper

func GetEnvWrapper(env string) (res string, err error)

Get environment variable with upper case only, if not exist, return error. Othewise return result of the environment variable.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL