progs/app3.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 28 Oct 2022 09:08:13 +0100
changeset 893 54a483a33763
parent 559 db5cb071644d
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
559
Christian Urban <urbanc@in.tum.de>
parents: 254
diff changeset
     1
val my_urls = """urban""".r
7
73cf4406b773 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
73cf4406b773 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
def crawl(url: String, n: Int) : Unit = {
73cf4406b773 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
  if (n == 0) ()
254
dcd4688690ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 97
diff changeset
     5
  else if (my_urls.findFirstIn(url) == None) { 
dcd4688690ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 97
diff changeset
     6
    println(s"Visiting: $n $url")
dcd4688690ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 97
diff changeset
     7
    get_page(url); () 
dcd4688690ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 97
diff changeset
     8
  }
7
73cf4406b773 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  else {
96
9fcd3de53c06 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    10
    println(s"Visiting: $n $url")
254
dcd4688690ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 97
diff changeset
    11
    for (u <- get_all_URLs(get_page(url))) crawl(u, n - 1)
7
73cf4406b773 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  }
73cf4406b773 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
}