Last active
July 3, 2018 02:51
-
-
Save takahashilabo/835bf8fdc0b06166f3dba6f5b79f6996 to your computer and use it in GitHub Desktop.
気象庁のページをスクレイピングして福岡地方の暴風警報を取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #気象警報・注意報 : 福岡県 取得 | |
| s = `curl "http://www.jma.go.jp/jp/warn/346_table.html"` | |
| File.open("dummy.html", "w") do |f| | |
| f.puts(s) | |
| end | |
| s = `xmllint --html --xpath '//table[@id="WarnTableTable"]' dummy.html` | |
| s2 = s.gsub('<tr>', '') | |
| .gsub(/<td.[^>]*>/, '') | |
| .gsub('</td>', ',') | |
| .gsub(/<a.[^>]*>/, '') | |
| .gsub('</a>', '') | |
| .gsub('福岡地方,福<br>岡<br>地<br>方<br>,', '') | |
| .gsub('京<br>築<br>,', '') | |
| .gsub('北九州地方,北<br>九<br>州<br>・<br>遠<br>賀<br>地<br>区<br>,', '') | |
| .gsub('筑豊地方,筑<br>豊<br>地<br>方<br>,', '') | |
| .gsub('筑後地方,筑<br>後<br>北<br>部<br>,', '') | |
| .gsub('筑<br>後<br>南<br>部<br>,', '') | |
| s3 = s2.split('</tr>') | |
| s3.delete_if do |e| | |
| e.size() == 0 or e[0] == '<' | |
| end | |
| puts "福岡地方・北九州地方・筑豊地方の以下の地域で暴風警報が発令されています。ご注意ください。" | |
| s3.each do |e| | |
| ee = e.split(',') | |
| break if ee[0] == '久留米市' | |
| puts ee[0] if ee[3] == '●' | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment