Created
February 15, 2015 01:25
-
-
Save mocyuto/95d868750fbc0a72932d to your computer and use it in GitHub Desktop.
GooglePlayからIcon画像のURLを引っ張ってくる
This file contains 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
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