UNPKG

stepwright

Version:

A powerful web scraping library built with Playwright

96 lines 3.31 kB
"use strict"; // ---------------------------- // Public API // ---------------------------- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.runScraper = runScraper; exports.runScraperWithCallback = runScraperWithCallback; const scraper_1 = require("./scraper"); const tab_executor_1 = require("./tab-executor"); // Re-export types __exportStar(require("./types"), exports); // Re-export utility functions __exportStar(require("./utils"), exports); // Re-export step executor functions __exportStar(require("./step-executor"), exports); // Re-export tab executor functions __exportStar(require("./tab-executor"), exports); /** * Run the scraper. * * @param {object} page - The page object. * @param {object} options - The options object. * * @since v1.0.0 * @author Muhammad Umer Farooq <umer@lablnet.com> * * @returns {object} - The data. * @since v1.0.0 * @company Framework Island */ async function runScraper(templates, options = {}) { const browser = await (0, scraper_1.getBrowser)(options.browser || { headless: true }); const context = await browser.newContext(); const allResults = []; // Run each tab sequentially – adjust to parallel if desired for (const tmpl of templates) { const page = await context.newPage(); try { const tabResults = await (0, tab_executor_1.executeTab)(page, tmpl, options.onResult); allResults.push(...tabResults); } finally { await page.close(); } } await browser.close(); return allResults; } /** * Run the scraper with a callback. This is a simpler alternative to async generators for real-time processing. * * @param {object} page - The page object. * @param {function} onResult - The onResult function. * @param {object} options - The options object. * * @since v1.0.0 * @author Muhammad Umer Farooq <umer@lablnet.com> * * @returns {void} - Nothing. * @since v1.0.0 * @company Framework Island */ async function runScraperWithCallback(templates, onResult, options = {}) { const browser = await (0, scraper_1.getBrowser)(options.browser || { headless: true }); const context = await browser.newContext(); try { // Run each tab sequentially for (const tmpl of templates) { const page = await context.newPage(); try { await (0, tab_executor_1.executeTab)(page, tmpl, onResult); } finally { await page.close(); } } } finally { await browser.close(); } } //# sourceMappingURL=index.js.map