Skip to content

Instantly share code, notes, and snippets.

@StrykerKKD
Created April 16, 2015 17:05
Show Gist options
  • Save StrykerKKD/287ad61999ed3a451fb3 to your computer and use it in GitHub Desktop.
Save StrykerKKD/287ad61999ed3a451fb3 to your computer and use it in GitHub Desktop.
Web scraping with Dart 2
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:html/parser.dart' as parser;
import 'package:html/dom.dart';
main() async {
http.Response response = await http.get('https://news.ycombinator.com/');
Document document = parser.parse(response.body);
await for (Element element in tagStream(document,'a')){
print(element.text);
}
}
Stream tagStream(Document document, String tag) async*{
for(Element element in document.getElementsByTagName(tag)){
yield element;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment