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

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(())
}