Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UEC休講情報スクレイピングコード Scala版
name := "Scala-UEC-Kyuuko"
version := "1.0"
scalaVersion := "2.12.1"
libraryDependencies ++= Seq(
"net.ruippeixotog" %% "scala-scraper" % "1.2.0",
"joda-time" % "joda-time" % "2.9.7"
)
import net.ruippeixotog.scalascraper.browser.JsoupBrowser
import net.ruippeixotog.scalascraper.dsl.DSL.Extract._
import net.ruippeixotog.scalascraper.dsl.DSL._
import net.ruippeixotog.scalascraper.model.Element
import org.joda.time.{DateTime, DateTimeZone}
/**
* Created by benevolent0505 on 17/01/26.
*/
case class Lesson(
schoolYear: String,
date: DateTime,
period: Int,
subject: String,
teacher: String,
remark: String
)
object Lesson {
def apply(s: Seq[String]): Lesson = {
val regexp = """(\d+)月(\d+)日.+""".r
val regexp(month, day) = s(1).trim
val year = DateTime.now(DateTimeZone.forID("Asia/Tokyo")).getYear()
val date = new DateTime(year, month.toInt, day.toInt, 0, 0)
new Lesson(s(0), date, s(2).toInt, s(3), s(4), s(5))
}
}
object Main extends App {
val browser = JsoupBrowser()
val doc = browser.get("http://kyoumu.office.uec.ac.jp/kyuukou/kyuukou.html")
val items: List[Element] = doc >> elementList("tr")
items.tail.map(_ >> elementList("td").map(_ >> text("td")))
.map(Lesson.apply)
.foreach(println)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment