-
-
Save koyachi/d802c607223888651b5719a38fd9e4d8 to your computer and use it in GitHub Desktop.
a web scraping script with Dart and html
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 'dart:io'; | |
import 'dart:async'; | |
import 'package:html/parser.dart'; | |
import 'package:html/dom.dart'; | |
main() { | |
final url = 'http://comic-walker.com/'; | |
getHtml(url).then((document) { | |
print(document.querySelector('title').text); | |
document.querySelectorAll('#mainContent > li h2 span').forEach((e) { | |
print(e.text); | |
}); | |
}); | |
} | |
Future<Document> getHtml(String url) => new HttpClient() | |
.getUrl(Uri.parse(url)) | |
.then((req) => req.close()) | |
.then((res) => | |
res.asyncExpand((bytes) => new Stream.fromIterable(bytes)).toList()) | |
.then((bytes) => parse(bytes, sourceUrl: url)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment