Skip to content

Instantly share code, notes, and snippets.

@mocyuto
Created February 15, 2015 01:25
Show Gist options
  • Save mocyuto/95d868750fbc0a72932d to your computer and use it in GitHub Desktop.
Save mocyuto/95d868750fbc0a72932d to your computer and use it in GitHub Desktop.
GooglePlayからIcon画像のURLを引っ張ってくる
def googlePlayIconUrl(appIdentifier: String): Option[String] = {
val googleImgTag = "div.cover-container img.cover-image"
def googlePlayUrl(appIdentifier: String): String = s"https://play.google.com/store/apps/details?id=$appIdentifier"
try {
val doc = Jsoup.connect(googlePlayUrl(appIdentifier)).get
Option(doc.select(googleImgTag).first.attr("src"))
} catch {
case e: HttpStatusException => {
// loggerに関しては、適当なものを定義してください。
logger.error(s"GooglePlayにアクセスできません。$appIdentifier")
None
}
case e: SocketTimeoutException => {
logger.error(s"GooglePlayにタイムアウトでアクセスできません。$appIdentifier")
None
}
case e: IOException => None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment