rust片段

[dependencies]
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "blocking"] }
html2md = "0.2"
use std::fs;
fn main() {
let url = "http://qlik.joinleader.net:8001/";
let output = "rust.md";
println!("Fetching url: {}", url);
let body = reqwest::blocking::get(url).unwrap().text().unwrap();
println!("Converting html to markdown...");
let md = html2md::parse_html(&body);
fs::write(output, md.as_bytes()).unwrap();
println!("Converted markdown has been saved in {}.", output);
}

  

[dependencies]
reqwest = { version = "0.10", features = ["json"] }
tokio = { version = "0.2", features = ["full"] }
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let resp = reqwest::get("https://httpbin.org/ip")
        .await?
        .json::<HashMap<String, String>>()
        .await?;
    println!("{:#?}", resp);
    Ok(())
}

  

 

posted @ 2022-07-02 23:05  CrossPython  阅读(25)  评论(0编辑  收藏  举报