page-executor
    TypeScript icon, indicating that this package has built-in type declarations

    1.3.0 • Public • Published

    page-executor

    Promise based pages code executor for Node.js

    Table of Contents

    Why

    Imagine you need to run one script across multiple sites (e.g., scrape data). You open site by site, wait until the content is loaded, and execute your script.

    It could work unless you have 20+ sites. To solve this problem, you can use this package and run multiple sites immediately to save your time.

    Features

    • [x] Emulates full DOM tree and gives access to elements
    • [ ] Add puppeteer to create screenshots and etc

    Installing

    Using npm:

    $ npm install page-executor

    Example

    Create an instance:

    const { PageExecutor } = require('page-executor');
    
    // Create a default instance
    const pageExecutor = new PageExecutor();
    // or create with default predicate
    const pageExecutor = new PageExecutor(({ document }) => {
      const rootElement = document.querySelector('button');
      return (rootElement && rootElement.innerHTML) || 'No element';
    });

    Get single link:

    // Use with one link
    pageExecutor
      .perPage('https://smile-track.web.app')
      .then((nodeTexts) => console.log(nodeTexts));

    Or get multiple links:

    const pageLinks = [
      'https://smile-track.web.app',
      'https://discord.com',
      'https://www.netflix.com/',
    ];
    
    pageExecutor
      .perPage(pageLinks)
      .then((nodeTexts) => console.log(nodeTexts));

    Pass custom predicate for each call:

    pageExecutor
      .perPage('https://smile-track.web.app', ({ document }) => document.title)
      .then((title) => console.log(title));
    
    executor
      .perPage('https://developer.mozilla.org', ({ document }) => document.querySelector('#skip-main').innerHTML)
      .then((label) => console.log(label));

    TypeScript

    page-executor includes TypeScript definitions.

    import { PageExecutor } from 'page-executor';
    const pageExecutor = new PageExecutor();

    License

    MIT

    Created with by Dmytro Vakulenko, 2021.

    Install

    npm i page-executor

    DownloadsWeekly Downloads

    2

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    6.91 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar