initial commit
This commit is contained in:
commit
61083535f7
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
1001
Cargo.lock
generated
Normal file
1001
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
9
Cargo.toml
Normal file
9
Cargo.toml
Normal 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
46
src/main.rs
Normal 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()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user