I am trying to follow the example here: https://rust-lang-nursery.github.io/rust-cookbook/web/scraping.html, which utilizes both Reqwest and Select in order to get an html response then parse the data.
I am using Reqwest version 0.10.4 and Select version 0.4.3 which are the versions it shows in the example. However, I am getting an error:
error[E0277]: the trait bound `reqwest::Response: std::io::Read` is not satisfied
--> src/main.rs:19:25
|
19 | Document::from_read(res)?
| ^^^ the trait `std::io::Read` is not implemented for `reqwest::Response`
|
::: /root/.cargo/registry/src/github.com-1ecc6299db9ec823/select-0.4.3/src/document.rs:31:25
|
31 | pub fn from_read<R: io::Read>(mut readable: R) -> io::Result<Document> {
| -------- required by this bound in `select::document::Document::from_read`
It seems like the from_read method takes in a Read type but the reqwest::get method returns a different type. Is there some sort of conversion that must be done first before the response is passed to the from_read method?
This is the example:
#[macro_use]
extern crate error_chain;
extern crate reqwest;
extern crate select;
use select::document::Document;
use select::predicate::Name;
error_chain! {
foreign_links {
ReqError(reqwest::Error);
IoError(std::io::Error);
}
}
fn main() -> Result<()> {
let res = reqwest::get("https://www.rust-lang.org/en-US/").await?;
Document::from_read(res)?
.find(Name("a"))
.filter_map(|n| n.attr("href"))
.for_each(|x| println!("{}", x));
Ok(())
}