feat: add __network/html-crawl-parse, __wasm/wasmtime-serde-demo

This commit is contained in:
2024-03-24 13:15:59 +08:00
parent 8adc5a58bc
commit f5a41fdb02
30 changed files with 3574 additions and 1 deletions

1686
__network/html-crawl-parse/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
[package]
name = "html-crawl-parse"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
base64 = "0.22.0"
reqwest = "0.12.1"
scraper = "0.19.0"
tokio = { version = "1.36.0", features = ["full"] }

View File

@@ -0,0 +1,33 @@
use base64::Engine;
use base64::engine::general_purpose::STANDARD;
use reqwest::Client;
use scraper::{Html, Selector};
type StdResult = Result<(), Box<dyn std::error::Error>>;
// from: https://mp.weixin.qq.com/s/5kwVXFobW1OJ5lU1nn9Vkw
#[tokio::main]
async fn main() -> StdResult {
let res = Client::new()
.get(String::from_utf8(STANDARD.decode("aHR0cDovL2Jvb2tzLnRvc2NyYXBlLmNvbS8=")?)?)
.send().await?;
let body = res.text().await?;
let document = Html::parse_document(&body);
let book_title_selector = Selector::parse("h3 > a")?;
for book_title in document.select(&book_title_selector) {
let title = book_title.text().collect::<Vec<_>>();
println!("Title: {}", title[0]);
}
let book_price_selector = Selector::parse(".price_color")?;
for book_price in document.select(&book_price_selector) {
let price = book_price.text().collect::<Vec<_>>();
println!("Price: {}", price[0]);
}
Ok(())
}