-
Notifications
You must be signed in to change notification settings - Fork 23
/
university.dart
31 lines (28 loc) · 933 Bytes
/
university.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import 'dart:convert';
import 'package:http/http.dart';
import 'package:html/parser.dart' show parse;
import 'package:html/dom.dart';
main(List<String> args) async {
final res = await get('https://en.wikipedia.org/wiki/List_of_universities_in_Myanmar');
final doc = parse(res.body);
// final text = doc.body.text;
final h3s = doc.querySelectorAll('h3');
// final reg = procRegion(h3s[1]);
final universities = <String, List<String>>{};
h3s.forEach((reg) {
universities.addAll(procRegion(reg));
});
print(json.encode(universities));
}
Map<String, List<String>> procRegion(Element reg) {
final name = reg.firstChild.text.trim();
if (!name.endsWith('Region') && !name.endsWith('State')) return {};
print(name);
final ul = reg.nextElementSibling;
assert (ul.localName == 'ul');
final lis = ul.querySelectorAll('li');
final list = lis.map((li) => li.text).toList();
return {
name: list,
};
}