@Grab(group='org.jsoup', module='jsoup', version='1.6.1') import org.jsoup.* import org.jsoup.select.* // 日本の15歳~64歳の人口割合を取得 yearFrom = "2006" yearTo = "2010" country = "jpn" base = "http://api.worldbank.org/countries/${country}/indicators/SP.POP.1564.TO.ZS" param = "?per_page=1000&date=${yearFrom}:${yearTo}" doc = Jsoup.connect("${base}${param}").get() for(elem in Selector.select("wb|data wb|data", doc)){ // 国名 country = elem.getElementsByTag("wb:country").eq(0).text() // 年 year = elem.getElementsByTag("wb:date").eq(0).text() // 値 value = elem.getElementsByTag("wb:value").eq(0).text() println("${country}:${year}:${value}") }
動作環境
groovy 1.8.2, JDK6 Update27, jsoup 1.6.1
0 件のコメント:
コメントを投稿