author | Christian Urban <urbanc@in.tum.de> |
Sun, 28 Jul 2019 01:00:41 +0100 | |
changeset 623 | 47a299e7010f |
parent 254 | dcd4688690ce |
permissions | -rw-r--r-- |
254
dcd4688690ce
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
97
diff
changeset
|
1 |
val http_pattern = """"https?://[^"]*"""".r |
7 | 2 |
|
3 |
def unquote(s: String) = s.drop(1).dropRight(1) |
|
4 |
||
254
dcd4688690ce
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
97
diff
changeset
|
5 |
def get_all_URLs(page: String) : Set[String] = |
96
9fcd3de53c06
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
6 |
http_pattern.findAllIn(page).map(unquote).toSet |
7 | 7 |
|
8 |
def crawl(url: String, n: Int) : Unit = { |
|
9 |
if (n == 0) () |
|
10 |
else { |
|
96
9fcd3de53c06
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
11 |
println(s"Visiting: $n $url") |
254
dcd4688690ce
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
97
diff
changeset
|
12 |
for (u <- get_all_URLs(get_page(url))) crawl(u, n - 1) |
7 | 13 |
} |
14 |
} |
|
15 |
||
254
dcd4688690ce
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
97
diff
changeset
|
16 |
crawl(some_start_URL, 2) |