1.3.0 • Published 3 years ago

page-executor v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

page-executor

comment: <> ([npm version(https://img.shields.io/npm/v/page-executor.svg?style=flat-square)](https://www.npmjs.org/package/page-executor)) comment: <> ([install size(https://packagephobia.now.sh/badge?p=page-executor)](https://packagephobia.now.sh/result?p=page-executor)) comment: <> ([npm downloads(https://img.shields.io/npm/dm/page-executor.svg?style=flat-square)](http://npm-stat.com/charts.html?package=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

  • 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.