Skip to content

Instantly share code, notes, and snippets.

@nemo-kaz
Created October 10, 2010 13:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nemo-kaz/619226 to your computer and use it in GitHub Desktop.
// g100pon #19 為替情報の取得
@Grab(group='net.sourceforge.nekohtml', module='nekohtml', version='1.9.14')
import org.cyberneko.html.parsers.SAXParser
class dummy {} // ver1.6 互換の為の class annotationとしての@grap
url = 'http://ja.exchange-rates.org/converter/JPY/BRL/100'
def parser = new XmlSlurper(new SAXParser())
def HTML = parser.parse(url)
def userIDs = HTML.'**'.findAll{
it.name() == 'SPAN' && it.@id == 'ctl00_M_lblToAmount' // <SPAN class="username">
}.collect{ it.text() } // A要素の値
userIDs.each{ id -> println "現在 [100] 円は [${id}] ブラジルレアル" }
// 円ドルレートはありがちそうなので 円レアルレートとしました。
// 急激な円高で、ブラジル債をやっている人は気が気ではないと思います。
// なのでレアルにしました。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment