Skip to content

Instantly share code, notes, and snippets.

@ali2236
Created November 8, 2020 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ali2236/14a12460a7b8f857e9e5c02583fff91c to your computer and use it in GitHub Desktop.
Save ali2236/14a12460a7b8f857e9e5c02583fff91c to your computer and use it in GitHub Desktop.
Filters a list of html elements based on their attributes
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