npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

pagehtml

v0.0.1

Published

A tool to grab and process a website's html.

Readme

Welcome to pageHtml

A tool to extract data from HTML. Dependencies include Puppeteer with Rebrowser patches, User-Agents, and JSDOM.

Installation

npm i pagehtml

Example Usage

Here is a basic example that demonstrates loading two different webpages. Each page's JSDOM instance is stored in an array property of the PageHTML class. We can then access these DOMs later with methods such as tables, links, and content.

Basic Example:

const PageHTML = require('pagehtml');

// Create the PageHTML object.
let pHtml = new PageHTML();

(async () => {
    // Get the webpage content for two distinct URLs and store in the dom property of the PageHTML class.
    await pHtml.get('https://www.example.com');
    await pHtml.get('https://en.wikipedia.org/wiki/List_of_Formula_One_Grand_Prix_winners');

    // close the browser and page.
    pHtml.close();

    // Grab all href links from the example.com page.
    // This will return an array of link objects as shown below.
    // [
    //   {
    //     href: 'https://www.iana.org/domains/example',
    //     nodeName: 'a',
    //     outerHTML: '<a href="https://www.iana.org/domains/example">More information...</a>',
    //     innerHTML: 'More information...',
    //     parentElement: 'p'
    //   }
    // ]
    let links = pHtml.links(0);
    console.log(links);

    // prints to console: https://www.iana.org/domains/example
    let href = links[0].href;
    console.log(href);

    // From the wikipedia link, return the third table.
    // This will return the array of arrays listed below:
    // [
    //     [
    //         'Rank',
    //         'Country',
    //         'Driver',
    //         'Wins',
    //         'Seasons active',
    //         'First win',
    //         'Last win'
    //     ],
    //     [
    //         '1',
    //         'United Kingdom',
    //         'Lewis Hamilton†',
    //         '105',
    //         '2007–',
    //         '2007 Canadian Grand Prix',
    //         '2024 Belgian Grand Prix'
    //     ],
    //     [
    //         '2',
    //         'Germany',
    //         'Michael Schumacher‡',
    //         '91',
    //         '1991–2006, 2010–2012',
    //         '1992 Belgian Grand Prix',
    //         '2006 Chinese Grand Prix'
    //     ],
    //     [
    //         '3',
    //         'Netherlands',
    //         'Max Verstappen†',
    //         '63',
    //         '2015–',
    //         '2016 Spanish Grand Prix',
    //         '2024 Qatar Grand Prix'
    //     ],
    //     ...
    // ]
    let tables = pHtml.tables(1)[2];
    console.log(tables);
})();

Passing a Referer:

In some cases it may be beneficial to pass a referer to the get method. This can be handled as follows:

await pHtml.get('https://en.wikipedia.org/wiki/List_of_Formula_One_Grand_Prix_winners', 'https://en.wikipedia.org/');

Handling Page Reroutes and Reloads

If you are interacting with the page to perform more browser automation beyond the scope of this API, you may find it advantagous to load the page, interact with it, and then grab the DOM of the page in its final state. This could be accomplished as follows:

// Create the PageHTML object.
let pHtml = new PageHTML();

// load a webpage
await pHtml.get('https://bot-detector.rebrowser.net/');

// perform browser and page interactions using pHtml.browser and pHtml.page which exposes the puppeteer class.

// grab the latest dom after page interactions are complete by calling the get method with no arguments.
await pHtml.get();

License

MIT

Authors

John Glauber

Contact

For any questions, comments, or suggestions please reach out via email to:

[email protected] https://github.com/jglauber/pageHtml