extract_custom method

Future<Online> extract_custom(
  1. String key,
  2. String customFunction, {
  3. List? args,
})

Extracts data using a custom JavaScript function and stores it in the context.

key is the key under which the extracted data will be stored in the context. customFunction is a string containing a JavaScript function to be executed. args (optional) is a list of arguments to be passed to the custom function.

Returns the Online instance for method chaining.

Example usage:

await online.extract_custom('customProductData', '''
  () => {
    return Array.from(document.querySelectorAll('div.product'))
      .map(div => ({
        name: div.querySelector('.name').textContent,
        price: parseFloat(div.querySelector('.price').textContent.slice(1))
      }));
  }
''');
var customProductData = ctx.get<List<Map<String, dynamic>>>('customProductData');

Implementation

Future<Online> extract_custom(String key, String customFunction,
    {List<dynamic>? args}) async {
  Show.action('extracting', 'custom data');
  var result = await (await page).evaluate(customFunction, args: args);
  ctx.set(key, result);
  return this;
}