Jsoupを使用すると、指定されたWebサイトからすべての予想データを抽出できます。もしtd
要素を選択しなければならない(各行は3つのテーブル・セルを有する)と、あなたが望む任意の変数をそれらのセルの値を割り当てることができ、行ごと
table.ratesTable > tbody > tr
次へ:最初に次のセレクタを使用して、すべての表の行を選択する必要が。あなたのコードは、この1のようになります。
Document doc = Jsoup.connect("http://www.x-rates.com/table/?from=USD&amount=1").get();
Elements rows = doc.select("table.ratesTable > tbody > tr");
for (Element row : rows) {
Elements tds = row.select("td");
String currency = tds.get(0).text();
Double rate1 = Double.valueOf(tds.get(1).text());
Double rate2 = Double.valueOf(tds.get(2).text());
System.out.printf("Currency: %s, rate1: %s, rate2: %s%n", currency, rate1, rate2);
}
このプログラムは、コンソール出力、次の生成:
Currency: Euro, rate1: 0.845569, rate2: 1.182635
Currency: British Pound, rate1: 0.768631, rate2: 1.301014
Currency: Indian Rupee, rate1: 64.134227, rate2: 0.015592
Currency: Australian Dollar, rate1: 1.266043, rate2: 0.789863
Currency: Canadian Dollar, rate1: 1.267137, rate2: 0.789181
Currency: Singapore Dollar, rate1: 1.360245, rate2: 0.735162
Currency: Swiss Franc, rate1: 0.96141, rate2: 1.040139
Currency: Malaysian Ringgit, rate1: 4.298091, rate2: 0.232661
Currency: Japanese Yen, rate1: 109.110914, rate2: 0.009165
Currency: Chinese Yuan Renminbi, rate1: 6.661812, rate2: 0.150109
Currency: Argentine Peso, rate1: 17.74499, rate2: 0.056354
Currency: Australian Dollar, rate1: 1.266043, rate2: 0.789863
Currency: Bahraini Dinar, rate1: 0.377148, rate2: 2.651478
Currency: Botswana Pula, rate1: 10.354673, rate2: 0.096575
Currency: Brazilian Real, rate1: 3.194036, rate2: 0.313084
Currency: Bruneian Dollar, rate1: 1.360245, rate2: 0.735162
Currency: Bulgarian Lev, rate1: 1.662835, rate2: 0.601383
Currency: Canadian Dollar, rate1: 1.267137, rate2: 0.789181
Currency: Chilean Peso, rate1: 646.170017, rate2: 0.001548
Currency: Chinese Yuan Renminbi, rate1: 6.661812, rate2: 0.150109
Currency: Colombian Peso, rate1: 2973.600291, rate2: 3.36E-4
Currency: Croatian Kuna, rate1: 6.248125, rate2: 0.160048
Currency: Czech Koruna, rate1: 22.130355, rate2: 0.045187
Currency: Danish Krone, rate1: 6.332396, rate2: 0.157918
Currency: Euro, rate1: 0.845569, rate2: 1.182635
Currency: Hong Kong Dollar, rate1: 7.8192, rate2: 0.12789
Currency: Hungarian Forint, rate1: 257.81906, rate2: 0.003879
Currency: Icelandic Krona, rate1: 105.635027, rate2: 0.009467
Currency: Indian Rupee, rate1: 64.134227, rate2: 0.015592
Currency: Indonesian Rupiah, rate1: 13357.499908, rate2: 7.5E-5
Currency: Iranian Rial, rate1: 32849.5, rate2: 3.0E-5
Currency: Israeli Shekel, rate1: 3.586513, rate2: 0.278822
Currency: Japanese Yen, rate1: 109.110914, rate2: 0.009165
Currency: Kazakhstani Tenge, rate1: 332.672501, rate2: 0.003006
Currency: South Korean Won, rate1: 1143.773759, rate2: 8.74E-4
Currency: Kuwaiti Dinar, rate1: 0.302319, rate2: 3.307765
Currency: Libyan Dinar, rate1: 1.37005, rate2: 0.7299
Currency: Malaysian Ringgit, rate1: 4.298091, rate2: 0.232661
Currency: Mauritian Rupee, rate1: 33.552148, rate2: 0.029804
Currency: Mexican Peso, rate1: 17.835986, rate2: 0.056066
Currency: Nepalese Rupee, rate1: 102.352456, rate2: 0.00977
Currency: New Zealand Dollar, rate1: 1.366238, rate2: 0.731937
Currency: Norwegian Krone, rate1: 7.93064, rate2: 0.126093
Currency: Omani Rial, rate1: 0.384499, rate2: 2.600784
Currency: Pakistani Rupee, rate1: 105.360213, rate2: 0.009491
Currency: Philippine Peso, rate1: 51.055889, rate2: 0.019586
Currency: Polish Zloty, rate1: 3.627166, rate2: 0.275697
Currency: Qatari Riyal, rate1: 3.642217, rate2: 0.274558
Currency: Romanian New Leu, rate1: 3.871704, rate2: 0.258284
Currency: Russian Ruble, rate1: 59.885203, rate2: 0.016699
Currency: Saudi Arabian Riyal, rate1: 3.751954, rate2: 0.266528
Currency: Singapore Dollar, rate1: 1.360245, rate2: 0.735162
Currency: South African Rand, rate1: 13.467078, rate2: 0.074255
Currency: Sri Lankan Rupee, rate1: 153.070914, rate2: 0.006533
Currency: Swedish Krona, rate1: 8.140123, rate2: 0.122848
Currency: Swiss Franc, rate1: 0.96141, rate2: 1.040139
Currency: Taiwan New Dollar, rate1: 30.365433, rate2: 0.032932
Currency: Thai Baht, rate1: 33.201131, rate2: 0.030119
Currency: Trinidadian Dollar, rate1: 6.7275, rate2: 0.148644
Currency: Turkish Lira, rate1: 3.539571, rate2: 0.28252
Currency: Emirati Dirham, rate1: 3.674458, rate2: 0.272149
Currency: British Pound, rate1: 0.768631, rate2: 1.301014
Currency: Venezuelan Bolivar, rate1: 9.977002, rate2: 0.100231
私はそれが役に立てば幸い。
これは完璧です! @SzymonStepniakありがとう! –
@OmerHenクール、私はあなたを助けることができてうれしいよ:) –