UrakawaMの日記: 某所用スクリプトその1
日記 by
UrakawaM
---
require 'net/http'
Net::HTTP.version_1_2 # おまじない
rows = [
"順位", "タイム", "ナンバー", "名前",
"チーム", "車種", "ミッション", "クラス",
"階級", "店舗", "日時"
]
# 匠は+32
courses = [
12, 13, 0, 1, 18, 19, 2, 3, 16, 17, 4, 5, 6, 7, 8, 9, 14, 15, 10, 11,
]
# サーバからランキング読み込み
response = nil;
Net::HTTP.start('xxxxxxx.xxxxxxxxxx.net', 80) { |http|
response = http.post('/ranking.php',
'jk_car=2&SEL_CAR=36&COURSE=36') # 85匠上級順
}
# 構造解析
str = response.body.gsub(/\{[^\}]*\}/, "").gsub(/<!--[^<]*>/, "") #htmlコメント(スクリプト)外し
# 大雑把な解析 (タグ外し、行頭空白はずし、行末空白はずししてそれっぽくスキャン)
datas = str.gsub(/<.*?>/, "").
gsub(/^\s*/,"").
gsub(/\s*$/,"").
scan(/([0-9]+)\n([0-9]\'[0-9][0-9]\"[0-9][0-9][0-9])\n([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)\n([SABCD]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)\n/)
# 解析結果表示
0.step(rows.size-1, 1) do |i|
print rows[i]+","
end
print "\n"
0.step(datas.size-1, 1) do |i|
0.step(datas[i].size-1, 1) do |j|
if (datas[i][j] != nil)
print datas[i][j]+","
elsif
print ","
end
end
print "\n"
end
---
85上級匠1枚目の結果をCSV形式で出力します。
htmlの解析が相当いい加減なのは、読み込み対象を決め打ちしてるからということで。
require 'net/http'
Net::HTTP.version_1_2 # おまじない
rows = [
"順位", "タイム", "ナンバー", "名前",
"チーム", "車種", "ミッション", "クラス",
"階級", "店舗", "日時"
]
# 匠は+32
courses = [
12, 13, 0, 1, 18, 19, 2, 3, 16, 17, 4, 5, 6, 7, 8, 9, 14, 15, 10, 11,
]
# サーバからランキング読み込み
response = nil;
Net::HTTP.start('xxxxxxx.xxxxxxxxxx.net', 80) { |http|
response = http.post('/ranking.php',
'jk_car=2&SEL_CAR=36&COURSE=36') # 85匠上級順
}
# 構造解析
str = response.body.gsub(/\{[^\}]*\}/, "").gsub(/<!--[^<]*>/, "") #htmlコメント(スクリプト)外し
# 大雑把な解析 (タグ外し、行頭空白はずし、行末空白はずししてそれっぽくスキャン)
datas = str.gsub(/<.*?>/, "").
gsub(/^\s*/,"").
gsub(/\s*$/,"").
scan(/([0-9]+)\n([0-9]\'[0-9][0-9]\"[0-9][0-9][0-9])\n([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)\n([SABCD]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)\n/)
# 解析結果表示
0.step(rows.size-1, 1) do |i|
print rows[i]+","
end
print "\n"
0.step(datas.size-1, 1) do |i|
0.step(datas[i].size-1, 1) do |j|
if (datas[i][j] != nil)
print datas[i][j]+","
elsif
print ","
end
end
print "\n"
end
---
85上級匠1枚目の結果をCSV形式で出力します。
htmlの解析が相当いい加減なのは、読み込み対象を決め打ちしてるからということで。
某所用スクリプトその1 More ログイン