add login
This commit is contained in:
parent
c2c7e1f8ee
commit
cb228930d9
2 changed files with 63 additions and 6 deletions
|
@ -69,8 +69,6 @@ async fn main() {
|
||||||
|
|
||||||
let user_agent = format!("uwm/{}", env!("CARGO_PKG_VERSION"));
|
let user_agent = format!("uwm/{}", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
let marks = marks::get_marks(config.username, config.password.unwrap(), &user_agent).await;
|
marks::get_marks(config.username, config.password.unwrap(), &user_agent).await;
|
||||||
|
|
||||||
println!("{:#?}", marks);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
65
src/marks.rs
65
src/marks.rs
|
@ -1,9 +1,68 @@
|
||||||
pub async fn get_marks(username: String, password: String, user_agent: &str) -> String {
|
use scraper::{Html, Selector};
|
||||||
format!("{}/{}/{}", username, password, user_agent)
|
use std::io::Write;
|
||||||
|
|
||||||
|
pub async fn get_marks(username: String, password: String, user_agent: &str) {
|
||||||
// Login
|
// Login
|
||||||
// https://cas.univ-paris8.fr/cas/login
|
let document = login(username, password, user_agent)
|
||||||
|
.await
|
||||||
|
.expect("Can't login");
|
||||||
|
|
||||||
|
let mut w = std::fs::File::create("temp.html").unwrap();
|
||||||
|
write!(&mut w, "{}", document.html()).unwrap();
|
||||||
|
|
||||||
// Marks
|
// Marks
|
||||||
// https://scolarite-etudiant.univ-paris8.fr/mondossierweb/#!notesView
|
// https://scolarite-etudiant.univ-paris8.fr/mondossierweb/#!notesView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn login(
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
user_agent: &str,
|
||||||
|
) -> Result<Html, Box<dyn std::error::Error>> {
|
||||||
|
let login_url = "https://cas.univ-paris8.fr/cas/login";
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder().user_agent(user_agent).build()?;
|
||||||
|
|
||||||
|
let login_page = Html::parse_document(&client.get(login_url).send().await?.text().await?);
|
||||||
|
|
||||||
|
// LT
|
||||||
|
let sel_lt = Selector::parse(r#"input[name="lt"]"#).unwrap();
|
||||||
|
let lt = login_page
|
||||||
|
.select(&sel_lt)
|
||||||
|
.next()
|
||||||
|
.unwrap()
|
||||||
|
.value()
|
||||||
|
.attr("value")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Execution
|
||||||
|
let sel_execution = Selector::parse(r#"input[name="execution"]"#).unwrap();
|
||||||
|
let execution = login_page
|
||||||
|
.select(&sel_execution)
|
||||||
|
.next()
|
||||||
|
.unwrap()
|
||||||
|
.value()
|
||||||
|
.attr("value")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let params = [
|
||||||
|
("username", username.as_str()),
|
||||||
|
("password", password.as_str()),
|
||||||
|
("_eventID", "submit"),
|
||||||
|
("submit", "SE CONNECTER"),
|
||||||
|
("lt", lt),
|
||||||
|
("execution", execution),
|
||||||
|
];
|
||||||
|
|
||||||
|
let html = client
|
||||||
|
.post(login_url)
|
||||||
|
.form(¶ms)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let document = Html::parse_document(&html);
|
||||||
|
|
||||||
|
Ok(document)
|
||||||
|
}
|
||||||
|
|
Reference in a new issue