equal
deleted
inserted
replaced
1 val http_pattern = """\"https?://[^\"]*\"""".r |
1 val http_pattern = """\"https?://[^\"]*\"""".r |
2 |
2 |
3 def unquote(s: String) = s.drop(1).dropRight(1) |
3 def unquote(s: String) = s.drop(1).dropRight(1) |
4 |
4 |
5 def get_all_URLs(page: String) : Set[String] = { |
5 def get_all_URLs(page: String) : Set[String] = { |
6 (http_pattern.findAllIn(page)).map { unquote(_) }.toSet |
6 http_pattern.findAllIn(page).map(unquote).toSet |
7 } |
7 } |
8 |
8 |
9 def crawl(url: String, n: Int) : Unit = { |
9 def crawl(url: String, n: Int) : Unit = { |
10 if (n == 0) () |
10 if (n == 0) () |
11 else { |
11 else { |
12 println("Visiting: " + n + " " + url) |
12 println(s"Visiting: $n $url") |
13 for (u <- get_all_URLs(get_page(url))) crawl(u, n - 1) |
13 for (u <- get_all_URLs(get_page(url))) crawl(u, n - 1) |
14 } |
14 } |
15 } |
15 } |
16 |
16 |