I an trying to build a webscraper via rust using reqwest library. reqwest = "0.11.10" scraper = "0.12.0"
I saw the example here: https://kadekillary.work/post/webscraping-rust/ I tried to do the same thing, but i am getting an error.
My code: `
extern crate reqwest;
extern crate scraper;
use scraper::{Html,Selector};
fn main() {
println!("WELCOME!");
scrape_the_news("https://www.examplewebsite.com");
}
fn scrape_the_news(url: &str) {
let mut urlsource = reqwest::get(url).unwrap();
assert!(resp.status().is_success());
}
`
I am getting an error, the error is:
no method named unwrap
found for opaque type impl Future<Output = Result<Response, reqwest::Error>>
in the current scope
Thank you
CodePudding user response:
The example you use is outdated.
reqwest::get
is now an async function : it return immediately a "future" of the result without blocking. If you want to get the actual result, you have to wait for it to be available using.await
on the future.with the edition 2018 or later, you don't need to use
extern crate
declarations anymore
I suggest you to get the examples from the official project : https://github.com/seanmonstar/reqwest/blob/master/examples/simple.rs