@Grab(group='org.jsoup', module='jsoup', version='1.6.1') import org.jsoup.* import org.jsoup.select.* // 各国の総人口を取得 yearFrom = "2010" yearTo = "2010" base = "http://api.worldbank.org/countries/all/indicators/SP.POP.TOTL" param = "?per_page=1000&date=${yearFrom}:${yearTo}" doc = Jsoup.connect("${base}${param}").get() for(elem in Selector.select("wb|data wb|data", doc)){ // 国ID country_id = elem.getElementsByTag("wb:country").eq(0).attr("id") // 国名 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_id}:${country}:${year}:${value}") }
動作環境
groovy 1.8.2, JDK6 Update27, jsoup 1.6.1
0 件のコメント:
コメントを投稿