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

web-content-extract

v1.0.1

Published

A library and command-line tool to extract clean content from web pages using Mozilla Readability and convert it to Markdown or JSON.

Readme

Web Content Extract

中文版本

A library and command-line tool to extract clean content from web pages using Mozilla Readability, with enhanced SEO metadata extraction and JSON output support.

Features

  • Extracts main content from web pages, filtering out ads, navigation, and other non-essential elements
  • Converts extracted content to clean Markdown format
  • Enhanced SEO metadata extraction including:
    • Standard meta tags (title, description, keywords, author)
    • Open Graph metadata
    • Schema.org itemprop metadata
    • rel="author" links
    • time tags for publication dates
  • Supports multiple output formats: Markdown, YAML Front Matter, and JSON
  • Can be used as a library in other projects or as a standalone CLI tool
  • Built with TypeScript and Node.js
  • Uses @mozilla/readability for accurate content extraction
  • Uses ofetch for robust HTTP requests with timeout handling

Installation

npm install web-content-extract

Usage as a Library

import { extractContent } from "web-content-extract";

// Basic content extraction
const result = await extractContent("https://example.com");
console.log(result.content); // Markdown content

// Content extraction with SEO metadata
const resultWithSeo = await extractContent("https://example.com", true);
console.log(resultWithSeo.title); // Article title
console.log(resultWithSeo.seo); // SEO metadata
console.log(resultWithSeo.content); // Markdown content

// JSON output example
console.log(JSON.stringify(resultWithSeo, null, 2));

Usage as a CLI Tool

Run the tool using npx:

npx web-content-extract <url> [options]

Arguments

  • <url>: The URL of the web page to extract content from (required)

Options

  • -o, --output <file>: Output file path (default: stdout)
  • -s, --seo: Include SEO metadata in the output
  • -j, --json: Output in JSON format

Examples

Extract content and output to stdout:

npx web-content-extract https://example.com

Extract content and save to a file:

npx web-content-extract https://example.com -o output.md

Extract content with SEO metadata in YAML Front Matter format:

npx web-content-extract https://example.com --seo

Extract content with SEO metadata in JSON format:

npx web-content-extract https://example.com --seo --json

API

extractContent(url: string, includeSeo?: boolean): Promise<ExtractedContent>

Extracts content from a web page.

Parameters:

  • url: The URL of the web page to extract content from
  • includeSeo: Whether to include SEO metadata (default: false)

Returns: An object with the following properties:

  • content: The extracted content in Markdown format
  • title: The title of the article
  • seo: SEO metadata (only if includeSeo is true)

ExtractedContent Interface

interface ExtractedContent {
  content: string;
  title?: string;
  seo?: SeoMetadata;
}

interface SeoMetadata {
  title?: string;
  description?: string;
  keywords?: string;
  author?: string;
  publishedTime?: string;
  siteName?: string;
  language?: string;
  openGraph?: {
    title?: string;
    type?: string;
    image?: string;
    url?: string;
    description?: string;
    siteName?: string;
    locale?: string;
  };
}

How It Works

  1. Fetch: Uses ofetch to retrieve the HTML content of the specified URL with a 10-second timeout
  2. Parse: Uses jsdom to create a DOM environment from the HTML
  3. Extract: Uses @mozilla/readability to identify and extract the main article content
  4. SEO Metadata: Extracts comprehensive SEO metadata from various sources:
    • Standard meta tags
    • Open Graph tags
    • Schema.org itemprop attributes
    • rel="author" links
    • time tags
  5. Convert: Uses turndown to convert the extracted HTML content to Markdown
  6. Output: Outputs the content in the requested format (Markdown, YAML Front Matter, or JSON)

Development

  1. Clone or download this repository
  2. Install dependencies:
    npm install
  3. Build the project:
    npm run build

Dependencies

License

MIT