Created
January 5, 2018 05:24
-
-
Save kxzk/c461d9af3405d82a3a984ef369686571 to your computer and use it in GitHub Desktop.
Scrape all links from Hacker News
This file contains 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 select; | |
use select::document::Document; | |
use select::predicate::Name; | |
fn main() { | |
hacker_news("https://news.ycombinator.com"); | |
} | |
fn hacker_news(url: &str) { | |
let mut resp = reqwest::get(url).unwrap(); | |
assert!(resp.status().is_success()); | |
Document::from_read(resp) | |
.unwrap() | |
.find(Name("a")) | |
.filter_map(|n| n.attr("href")) | |
.for_each(|x| println!("{}", x)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment