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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mmiscool/scrape_to_markdown

v1.0.7

Published

A library to scrape articles from the web and convert them into Markdown format.

Downloads

288

Readme

Scrape to markdown

This project extracts the functionality of fetching a URL and generating a markdown string from clipper.js and packages it as a library that can be included in to your project using NPM.

Scraper to Markdown is a lightweight JavaScript library that allows you to scrape articles or web pages and convert their content into Markdown format. This is particularly useful for archiving, content generation, or data processing tasks.

Features

  • Extracts main content from web pages.
  • Converts HTML content into Markdown using Turndown.
  • Handles GitHub Flavored Markdown (GFM) for better compatibility.
  • Fallback mechanism for handling URLs that return raw Markdown.
  • Built-in support for readability parsing via @mozilla/readability.

Installation

Install the library using npm:

npm install @mmiscool/scrape_to_markdown -s

Usage

Import the Library

import { scrapeToMarkdown } from '@mmiscool/scrape_to_markdown';

Scrape a Web Page to Markdown

(async () => {
    const url = 'https://example.com/some-article';
    try {
        const markdown = await scrapeToMarkdown(url);
        console.log(markdown);
    } catch (error) {
        console.error('Error scraping the URL:', error);
    }
})();

Fallback for Raw Markdown URLs

The library can handle cases where the URL directly provides Markdown content. It will return the raw Markdown if no HTML is detected.

API

scrapeToMarkdown(url: string): Promise<string>

Scrapes the content from the provided URL and converts it to Markdown.

  • Parameters:
    • url: The URL of the web page to scrape.
  • Returns: A Promise resolving to the Markdown content.

extract_from_url(page: string): Promise<string>

Uses JSDOM and @mozilla/readability to extract and convert the primary content from a web page into Markdown.

extract_from_html(html: string): Promise<string>

Converts raw HTML input into Markdown.

oldScrapeToMarkdown(url: string): Promise<string>

Legacy scraper for handling edge cases or simpler scraping needs.

Dependencies

This library relies on the following NPM packages:

Examples

Scraping a Blog Post

import { scrapeToMarkdown } from '@mmiscool/scrape_to_markdown';

(async () => {
    const url = 'https://medium.com/some-blog-post';
    const markdown = await scrapeToMarkdown(url);
    console.log(markdown);
})();

Converting Raw HTML to Markdown

import { extract_from_html } from '@mmiscool/scrape_to_markdown';

const html = `
    <article>
        <h1>Example Article</h1>
        <p>This is an example paragraph.</p>
    </article>
`;

(async () => {
    const markdown = await extract_from_html(html);
    console.log(markdown);
})();

Credits

Clipper uses the following open source libraries:

License

  • Apache 2.0