Skip to content

Instantly share code, notes, and snippets.

@nagaki
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nagaki/9828581 to your computer and use it in GitHub Desktop.
Save nagaki/9828581 to your computer and use it in GitHub Desktop.
気象庁の天気データ「日ごとの値」から、JavaScriptでデータを取得する
// 気温
var a = []; jQuery.each($('#tablefix1')[0].rows, function(i, val){ if(i > 3){a.push(parseFloat(val.cells[7].innerHTML));}}); console.log(a);
// 天気
var a = []; jQuery.each($('#tablefix1')[0].rows, function(i, val){ if(i > 3){var s = val.cells[20].innerHTML[0]; var p; switch(s){ case "晴": case "快": p = 1; break; case "曇": p = 2; break; case "雨": case "雪": case "大": p = 3; break; default: p = 2;} a.push(p);}}); console.log(a);
// 値を格納する為の配列を作成
var a = [];
// テーブルの行を取得
var rows = $('#tablefix1')[0].rows;
jQuery.each(rows, function(i, val) {
if (i > 3) { // ヘッダ行などをスキップ
// cellsの値からinnerHTMLでテキストを取得できる
a.push(parseFloat(val.cells[8].innerHTML));
}
});
console.log(a);
// 値を格納する為の配列を作成
var a = [];
// テーブルの行を取得
var rows = $('#tablefix1')[0].rows;
jQuery.each(rows, function(i, val) {
if (i > 3) { // ヘッダ行などをスキップ
var p;
// 一文字目にフォーカスして[晴, 曇, 雨]を判定する
var s = val.cells[20].innerHTML[0];
switch (s) {
case "晴":
case "快":
p = 1;
break;
case "曇":
p = 2;
break;
case "雨":
case "雪":
case "大":
p = 3;
break;
default:
p = 2;
}
a.push(p);
}
});
console.log(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment