Created
November 8, 2020 19:34
-
-
Save ali2236/14a12460a7b8f857e9e5c02583fff91c to your computer and use it in GitHub Desktop.
Filters a list of html elements based on their attributes
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 'package:html/parser.dart'; | |
void main() { | |
var document = parse(body); | |
var selectElements = document | |
.getElementsByClassName('hello') | |
.where((element) => element.attributes['data-time'] == '9112020') | |
.map((item) => item.text) | |
.toList(); | |
print(selectElements); | |
} | |
var body = ''' | |
<table> | |
<tr class="hello" data-country="Germany" data-time="8112020">lorem ipsum1</tr> | |
<tr class="hello" data-country="Turkey" data-time="8112020">lorem ipsum2</tr> | |
<tr class="hello" data-country="Germany" data-time="9112020">lorem ipsum3</tr> | |
<tr class="hello" data-country="Turkey" data-time="9112020">lorem ipsum4</tr> | |
</table> | |
'''; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment