This commit is contained in:
Michael Lehmann
2024-04-09 22:44:25 +02:00
commit 04030d4aa2
4 changed files with 1761 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

1713
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

11
Cargo.toml Normal file
View File

@@ -0,0 +1,11 @@
[package]
name = "sl-update"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
regex = "1.10.4"
reqwest = { version = "0.12.3", features = ["blocking"] }
scraper = "0.19.0"

36
src/main.rs Normal file
View File

@@ -0,0 +1,36 @@
use scraper::{Html, Selector};
use regex::Regex;
use std::process::exit;
fn main() {
let standins_url = "https://www.bscyb.ch/tabelle-sl";
let response = reqwest::blocking::get(standins_url).unwrap().text().unwrap();
let document = Html::parse_document(&response);
let row_selector = Selector::parse("tr").unwrap();
let ranks = document.select(&row_selector).map(|x| x.html());
let re_pattern = match Regex::new(r"<td[^>]*>([^<]+)") {
Ok(re_pattern) => re_pattern,
Err(error) => {
eprintln!("Failed to compile pattern. Error {error}");
exit(1);
}
};
for rank in ranks {
let mut row = vec![];
for cap in re_pattern.captures_iter(&rank) {
row.push(cap.get(1).unwrap().as_str());
}
println!("row: {:?}", row);
}
}