Created
February 27, 2022 11:04
-
-
Save YumNumm/06de580274ec9d7dac19025eb517f28f 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
import 'package:html/parser.dart' show parse; | |
import 'package:http/http.dart' as http; | |
import 'package:intl/intl.dart'; | |
Future<void> main(List<String> args) async { | |
const String url = "https://typhoon.yahoo.co.jp/weather/jp/earthquake/list/"; | |
final target = Uri.parse(url); | |
final res = await http.get(target); | |
if (res.statusCode != 200) { | |
print("ERROR"); | |
return; | |
} | |
final doc = parse(res.body); | |
final result = doc | |
.querySelectorAll("#main > .yjw_main_md > #eqhist > table > tbody > tr"); | |
List<EQLog> eqList = []; | |
int counter = 0; | |
for (var e in result) { | |
if (counter == 0) { | |
counter++; | |
continue; | |
} | |
List<String> temp = []; | |
for (var element in e.children) { | |
temp.add(element.text); | |
} | |
eqList.add(EQLog.fromList(temp)); | |
} | |
for (var e in eqList) { | |
print( | |
"時刻: ${e.time}, 場所:${e.place}, 最大震度:${e.maxIntensity}, マグニチュード: ${e.magunitude}"); | |
} | |
} | |
class EQLog { | |
final DateTime time; | |
final String place; | |
final double magunitude; | |
final String maxIntensity; | |
EQLog({ | |
required this.time, | |
required this.place, | |
required this.magunitude, | |
required this.maxIntensity, | |
}); | |
EQLog.fromList(List<String> l) | |
: time = DateFormat("yyyy年MM月dd日 HH時mm分ごろ").parseStrict(l[0]), | |
place = l[1], | |
magunitude = double.parse(l[2]), | |
maxIntensity = l[3]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment