Serializing Web Scrapper to JSON

let args= Cli::parse();

    let v= &args.pattern;


    let res=reqwest::get(v)

 let document= Document::from(res.as_str());


        .filter_map(|n| n.attr("src"))
        .for_each(|x| println!("{}{}",v, x));

        let file = File::create("a")?;
    let mut writer = BufWriter::new(file);
    serde_json::to_writer(&mut writer, &x)?;

Hello rustaceans, I'm stuck please I need help, I'm working on a web scrapper to save image link to a json file.I can't access the x in the for_each loop outside it. The x is the image links. I'm a beginner in rust. Thanks a lot

let list_of_x: Vec<_> = document.find(Name("img"))
        .filter_map(|n| n.attr("src"))

Try with that.

1 Like

Okay. Thanks a lot. It work :hugs::hugs::hugs::hugs:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.