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