Skip to content

when use scraper to parse html and concurrent task in tauri::command, there is an error: has type scraper::Html which is not Send #12598

Answered by hahazexia
hahazexia asked this question in Q&A
Discussion options

You must be logged in to vote

rust-scraper/scraper#206 (comment)

async fn worker() {
    let html = reqwest::get("https://www.rust-lang.org").await.unwrap();
    let html = html.text().await.unwrap();
    let links = {
      let document = scraper::Html::parse_document(&html);
      let selector = scraper::Selector::parse("a").unwrap();
      document.select(&selector).map(|element| element.attr("href").unwrap().to_owned()).collect::<Vec<_>>()
    };
    for href in links {
        let html = reqwest::get(href).await.unwrap();
        let html = html.text().await.unwrap();
        let document = scraper::Html::parse_document(&html);
    }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hahazexia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant