feat: add __network/html-crawl-parse, __wasm/wasmtime-serde-demo
This commit is contained in:
1686
__network/html-crawl-parse/Cargo.lock
generated
Normal file
1686
__network/html-crawl-parse/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
__network/html-crawl-parse/Cargo.toml
Normal file
12
__network/html-crawl-parse/Cargo.toml
Normal 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"] }
|
||||
33
__network/html-crawl-parse/src/main.rs
Normal file
33
__network/html-crawl-parse/src/main.rs
Normal 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(())
|
||||
}
|
||||
Reference in New Issue
Block a user