Created
January 26, 2017 16:21
-
-
Save benevolent0505/fdcbd97e67c6b6bb328b3f2a81999bb7 to your computer and use it in GitHub Desktop.
UEC休講情報スクレイピングコード Scala版
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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