https://github.com/qsctech/jw-scraper-rs
浙江大学教务网爬虫库
https://github.com/qsctech/jw-scraper-rs
Last synced: about 1 year ago
JSON representation
浙江大学教务网爬虫库
- Host: GitHub
- URL: https://github.com/qsctech/jw-scraper-rs
- Owner: QSCTech
- License: mit
- Archived: true
- Created: 2019-02-13T14:07:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-28T06:36:46.000Z (over 6 years ago)
- Last Synced: 2025-04-06T11:47:42.996Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 137 KB
- Stars: 6
- Watchers: 13
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### ZJU-JWB scraper
[](https://travis-ci.org/QSCTech/jw-scraper-rs)
[](https://coveralls.io/github/QSCTech/jw-scraper-rs?branch=master)
[](https://crates.io/crates/zju-jw-scraper)
[](https://github.com/QSCTech/jw-scraper-rs/blob/master/LICENSE)
[](https://docs.rs/zju-jw-scraper)
#### service
```rust,ignore
#[async_trait]
pub trait JWService {
type Err;
async fn login(&self, stu_id: &str, password: &str) -> Result;
async fn get_course_info(&self, code: &str) -> Result;
async fn get_courses(
&self,
stu_id: &str,
school_year: SchoolYear,
semester: CourseSemester,
cookie: &str,
) -> Result, Self::Err>;
async fn get_exams(
&self,
stu_id: &str,
school_year: SchoolYear,
semester: ExamSemester,
cookie: &str,
) -> Result, Self::Err>;
async fn get_scores(&self, stu_id: &str, cookie: &str) -> Result, Self::Err>;
async fn get_major_scores(
&self,
stu_id: &str,
cookie: &str,
) -> Result, Self::Err>;
async fn get_total_credit(&self, stu_id: &str, cookie: &str) -> Result;
}
```
The `JWService` is implemented for all types which implements [`interfacer_http::HttpClient`](https://docs.rs/interfacer-http/0.2/interfacer_http/trait.HttpClient.html).
You can refer to `src/test.rs` for all use cases.
#### client
You can use this crate with `client` feature, like this:
```toml
zju-jw-scraper = { version = "0.2", features = ["client"] }
```
Then, you can use default client provided by `interfacer-http-hyper`:
```rust,no_run
use zju_jw_scraper::{client::client, JWService};
#[tokio::test]
async fn test_login() -> Result<(), Box> {
let service = client("http://jwbinfosys.zju.edu.cn".parse()?);
let cookie = service.login("319000000", "test").await?;
assert!(!cookie.is_empty());
Ok(())
}
```
However, the default client can only handle requests on HTTP, if you want to use other protocol like HTTPS, you need other [`Connect`](https://docs.rs/hyper/0.13.0-alpha.1/hyper/client/connect/trait.Connect.html).
As the example `connector`:
```rust,no_run
use hyper_tls::HttpsConnector;
use zju_jw_scraper::{client::client_on, JWService};
#[tokio::main]
async fn main() -> Result<(), Box> {
let service = client_on("https://jw.zjuqsc.com".parse()?, HttpsConnector::new()?);
let cookie = service.login("319000000", "test").await?;
assert!(!cookie.is_empty());
Ok(())
}
```
#### test
Run basic tests:
```bash
cargo test
```
To test this crate fully, create a config file `test-settings.toml`, and fill it referring to `test-settings.toml.sample`. Then run tests:
```bash
cargo test --all --all-features
```
As an alternative, you can configure tests using environment variables with prefix `TEST_`.
```bash
TEST_stu_id=3190000000 cargo test --all --all-features
```
> Environment variables always have higher priority.