author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Sun, 21 Sep 2014 23:23:43 +0100 | |
changeset 254 | dcd4688690ce |
parent 97 | 60a3ba90dd53 |
child 330 | 0806e45d873c |
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 |
val my_urls = """urbanc""".r |
3 |
val email_pattern = |
|
4 |
"""([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})""".r |
|
5 |
||
254
dcd4688690ce
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
97
diff
changeset
|
6 |
def print_str(s: String) = |
dcd4688690ce
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
97
diff
changeset
|
7 |
if (s == "") () else println(s) |
dcd4688690ce
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
97
diff
changeset
|
8 |
|
7 | 9 |
def crawl(url: String, n: Int) : Unit = { |
10 |
if (n == 0) () |
|
11 |
else { |
|
96
9fcd3de53c06
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
12 |
println(s"Visiting: $n $url") |
7 | 13 |
val page = get_page(url) |
254
dcd4688690ce
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
97
diff
changeset
|
14 |
print_str(email_pattern.findAllIn(page).mkString("\n")) |
dcd4688690ce
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
97
diff
changeset
|
15 |
for (u <- get_all_URLs(page).par) crawl(u, n - 1) |
7 | 16 |
} |
17 |
} |