extract_html method
Extracts HTML content from elements matching the selector and stores it in the context.
selector is the AbstractSelector to find elements.
key is the key under which the extracted data will be stored in the context.
innerHtml if true, extracts inner HTML instead of outer HTML.
Returns the Online instance for method chaining.
Example usage:
await online
.extract_html(Css('article.main-content'), 'articleHtml')
.extract_html(Css('p'), 'paragraphsHtml', innerHtml: true);
var articleHtml = ctx.get<List<String>>('articleHtml');
var paragraphsHtml = ctx.get<List<String>>('paragraphsHtml');
Implementation
Future<Online> extract_html(AbstractSelector selector, String key,
{bool innerHtml = false}) async {
Show.action('extracting', 'HTML', 'from', selector.selector);
await (await page).waitForSelector(selector.selector);
var htmlContents = await (await page).evaluate('''(selector, innerHtml) => {
return Array.from(document.querySelectorAll(selector)).map(e => innerHtml ? e.innerHTML : e.outerHTML);
}''', args: [selector.selector, innerHtml]);
ctx.set(key, List<String>.from(htmlContents));
return this;
}