@Grab(group='org.jsoup', module='jsoup', version='1.6.1') import org.jsoup.* import org.jsoup.select.* // 日本とUnited Statesの女性の人口割合を取得 yearFrom = "2010" yearTo = "2010" countries = "jpn;usa" base = "http://api.worldbank.org/countries/${countries}/indicators/SP.POP.TOTL.FE.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 件のコメント:
コメントを投稿