Last active
August 29, 2015 14:05
-
-
Save eiryu/98a714e1b40549347d9a to your computer and use it in GitHub Desktop.
GebでQiita Organizationごとの平均被ストック数を調べてみた ref: http://qiita.com/eiryu/items/a6cadabaa025d31c2e08
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
// Groovy Version: 2.2.1 JVM: 1.8.0_20 Vendor: Oracle Corporation OS: Mac OS X | |
@Grapes([ | |
@Grab('org.seleniumhq.selenium:selenium-support:2.41.0'), | |
@Grab('org.seleniumhq.selenium:selenium-htmlunit-driver:2.41.0'), | |
@Grab('org.gebish:geb-core:0.9.2') | |
]) | |
import geb.Browser | |
def sites = [] | |
Browser.drive { | |
go "http://qiita.com/organizations" | |
// 各Organizationページへのリンク | |
$('.organizationsList_orgName a').each { | |
def site = new Site() | |
site.companyName = it.text() | |
site.url = it.attr('href') | |
sites.add(site) | |
} | |
sites.each { | |
go it.url | |
println title | |
// 投稿数、ストックされた数を取得 | |
// :first とか使えないのでこう書く | |
it.post = $('.organizationStatsSummary_count', 0).text() | |
it.stocked = $('.organizationStatsSummary_count', 1).text() | |
} | |
}.quit() | |
println '|会社名|投稿数|被ストック数|平均被ストック数|' | |
println '|:--|--:|--:|--:|' | |
sites.each { | |
def averageStocked = new BigDecimal(it.stocked.toBigDecimal() / it.post.toBigDecimal()) | |
// 小数点第2位を四捨五入 | |
def roundupAverageStocked = averageStocked.setScale(1, BigDecimal.ROUND_HALF_UP) | |
println "|${it.companyName}|${it.post}|${it.stocked}|${roundupAverageStocked}|" | |
} | |
class Site { | |
def companyName | |
def url | |
def stocked | |
def post | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment