Skip to content
This repository has been archived by the owner on Jul 29, 2021. It is now read-only.

Commit

Permalink
add-HRefListFromUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-adam committed Aug 30, 2019
1 parent d8832bf commit 9288696
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package pl.writeonly.re.shared.hyde

import scala.io.Source
import scala.util.matching.Regex

import scalaz.Scalaz._

object HRefListFromUrl extends (String => List[String]) {

val r: Regex = """<a href="(.*)">(.*)</a>""".r

override def apply(url: String): List[String] = url |> html |> hRefList

def html(url: String): String = Source.fromURL(url).mkString

def hRefList(html: String): List[String] =
(for { m <- r.findAllMatchIn(html) } yield m.group(1)).toList

}
24 changes: 8 additions & 16 deletions re/shared/src/main/scala/pl/writeonly/re/shared/hyde/Hyde.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
package pl.writeonly.re.shared.hyde

import scala.io.Source
object Hyde {

class Hyde {
val url = "https://www.writeonly.pl/"

val r = """"
<a href="(.*)">(.*)</a>
""".r
val todoUrls = List(url)
val allUrls = List(url)

def fromURL(url: String): Iterator[String] = {
val html = Source.fromURL(url)
val s = html.mkString
s match {
case r(href, body) => {

}
}

// r.findAllMatchIn(s)
for { m <- r.findAllIn(s) } yield m
def main(args: Array[String]): Unit = {
val links = todoUrls.map(HRefListFromUrl)
print(links)
}

}

0 comments on commit 9288696

Please sign in to comment.