Created
April 16, 2015 17:05
-
-
Save StrykerKKD/287ad61999ed3a451fb3 to your computer and use it in GitHub Desktop.
Web scraping with Dart 2
This file contains 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: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