@Grab(group='org.jsoup', module='jsoup', version='1.6.1') import org.jsoup.* import org.jsoup.select.* // 各国の首都名を取得 base = "http://api.worldbank.org/countries" param = "?per_page=1000" doc = Jsoup.connect("${base}${param}").get() for(elem in Selector.select("wb|countries wb|country", doc)){ region = elem.getElementsByTag("wb:region").eq(0).text() if( region.equals("Aggregates") )continue; // ISO 3166-1 alpha-2 code country_id = elem.getElementsByTag("wb:iso2Code").eq(0).text() // 国名 country = elem.getElementsByTag("wb:name").eq(0).text() // 首都 capitalCity = elem.getElementsByTag("wb:capitalCity").eq(0).text() println("${country_id}:${country}:${capitalCity}") }
動作環境
groovy 1.8.2, JDK6 Update27, jsoup 1.6.1
0 件のコメント:
コメントを投稿