initial commit

This commit is contained in:
Max Hohlfeld 2022-12-21 23:31:22 +01:00
commit 61083535f7
4 changed files with 1057 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

1001
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "lfs_scraper"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11.13", features = ["blocking"] }

46
src/main.rs Normal file
View File

@ -0,0 +1,46 @@
struct RemainingPlace {
id: String,
description: String,
date: String,
free: usize
}
fn main() -> Result<(), reqwest::Error> {
// const URL: &str = "https://www.lfs.sachsen.de/restplatzboerse-5152.html";
const URL: &str = "http://127.0.0.1:8080/tip.html";
let body = reqwest::blocking::get(URL).unwrap().text().unwrap();
let start = body.find("<tbody").unwrap();
let end = body.find("</tbody>").unwrap();
let table = &body[start..=(end + 7)];
let mut places: Vec<RemainingPlace> = Vec::new();
let mut iter = table.lines();
while let Some(line) = iter.next() {
if line.contains("<tr>") {
let id = parse_node(iter.next().unwrap());
let description = parse_node(iter.next().unwrap());
let date = parse_node(iter.next().unwrap());
let free = parse_node(iter.next().unwrap()).parse().unwrap();
let place = RemainingPlace { id, description, date, free };
places.push(place);
}
}
for place in places {
println!("{} - {} - {} - {}", place.id, place.description, place.date, place.free);
}
Ok(())
}
fn parse_node(input: &str) -> String {
let start = input.find(">").unwrap();
let end = input.find("</").unwrap();
input[(start + 1)..end].to_string()
}