extract_multiple method
Extracts multiple data points from the page and stores them in the context.
extractions
is a map where keys are names for the data points and values are maps containing:
- 'selector': AbstractSelector to find elements
- 'attribute' (optional): attribute to extract instead of text content
Returns the Online instance for method chaining.
Example usage:
await online.extract_multiple({
'title': {'selector': Css('h1')},
'description': {'selector': Css('meta[name="description"]'), 'attribute': 'content'},
'price': {'selector': Css('.product-price'), 'attribute': 'data-price'}
});
var title = ctx.get<List<String>>('title');
var description = ctx.get<List<String>>('description');
var price = ctx.get<List<String>>('price');
Implementation
Future<Online> extract_multiple(
Map<String, Map<String, dynamic>> extractions) async {
Show.action('extracting', 'multiple data points');
for (var entry in extractions.entries) {
var selector = entry.value['selector'] as AbstractSelector;
var attribute = entry.value['attribute'] as String?;
await extract_text(selector, entry.key, attribute: attribute);
}
return this;
}