-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
38 lines (28 loc) · 869 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extern crate hyper;
extern crate regex;
use hyper::client::Client;
use std::io::Read;
use regex::Regex;
fn main() {
let client = Client::new();
let mut url = String::new();
// Read URL from user input
println!("Enter URL:");
std::io::stdin().read_line(&mut url).unwrap();
// Trim newline from URL string
url = url.trim().to_string();
// Retrieves page
let mut response = client.get(url).send().unwrap();
// Initiate storage for our page
let mut body = String::new();
// Store our page's body
response.read_to_string(&mut body).unwrap();
// We define a regex pattern to scrape links from our page
let re = Regex::new(r#"<a[^>]*href="([^"]*)""#).unwrap();
// Iterate over our link vector
for cap in re.captures_iter(&body) {
let link = &cap[1];
// Log each link to console
println!("Link: {}", link);
};
};