Created
November 3, 2018 21:08
-
-
Save evilpie/6ab2ac570cd65345b04a1b7e8507a5d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compiling rust-scraper v0.1.0 (file:///home/tom/Desktop/rust-scraper) | |
warning: unused import: `cssparser::ParseError` | |
--> src/main.rs:9:5 | |
| | |
9 | use cssparser::ParseError; | |
| ^^^^^^^^^^^^^^^^^^^^^ | |
| | |
= note: #[warn(unused_imports)] on by default | |
error[E0277]: the trait bound `cssparser::ParseError<'_, selectors::parser::SelectorParseErrorKind<'_>>: std::error::Error` is not satisfied | |
--> src/main.rs:29:20 | |
| | |
29 | let selector = Selector::parse("a")?; | |
| ^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `cssparser::ParseError<'_, selectors::parser::SelectorParseErrorKind<'_>>` | |
| | |
= note: required because of the requirements on the impl of `std::convert::From<cssparser::ParseError<'_, selectors::parser::SelectorParseErrorKind<'_>>>` for `std::boxed::Box<dyn std::error::Error>` | |
= note: required by `std::convert::From::from` | |
error: aborting due to previous error | |
For more information about this error, try `rustc --explain E0277`. | |
error: Could not compile `rust-scraper`. | |
To learn more, run the command again with --verbose. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate reqwest; | |
extern crate scraper; | |
extern crate cssparser; | |
extern crate selectors; | |
use scraper::Html; | |
use scraper::Selector; | |
use cssparser::ParseError; | |
#[derive(Debug)] | |
struct MyParseError<'i>(cssparser::ParseError<'i, selectors::parser::SelectorParseErrorKind<'i>>); | |
impl<'i> std::error::Error for MyParseError<'i> {} | |
impl<'i> std::fmt::Display for MyParseError<'i> { | |
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | |
write!(f, "ParseError") | |
} | |
} | |
fn main() -> Result<(), Box<std::error::Error>> { | |
let html = reqwest::get("https://hg.mozilla.org/integration/mozilla-inbound/")?.text()?; | |
// println!("html: {:?}", body); | |
let document = Html::parse_document(&html); | |
let selector = Selector::parse("a")?; | |
for a in document.select(&selector) { | |
println!("{} {}", a.value().attr("href").unwrap(), a.text().next().unwrap()); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment