5.45.0 • Published 2 months ago

metascraper-uol v5.45.0

Weekly downloads
688
License
MIT
Repository
github
Last release
2 months ago

Last version Coverage Status Build Status Dependency Status NPM Status

A library to easily scrape metadata from an article on the web using Open Graph, JSON+LD, regular HTML metadata, and series of fallbacks.

Table of Contents

Getting Started

metascraper is library to easily scrape metadata from an article on the web using Open Graph metadata, regular HTML metadata, and series of fallbacks.

It follows a few principles:

  • Have a high accuracy for online articles by default.
  • Make it simple to add new rules or override existing ones.
  • Don't restrict rules to CSS selectors or text accessors.

Installation

$ npm install metascraper --save

Usage

Let's extract accurate information from the following article:

npm.io

Then call metascraper with the rules bundle you want to apply for extracting content:

const metascraper = require('metascraper')([
  require('metascraper-author')(),
  require('metascraper-date')(),
  require('metascraper-description')(),
  require('metascraper-image')(),
  require('metascraper-logo')(),
  require('metascraper-clearbit')(),
  require('metascraper-publisher')(),
  require('metascraper-title')(),
  require('metascraper-url')()
])

const got = require('got')

const targetUrl = 'http://www.bloomberg.com/news/articles/2016-05-24/as-zenefits-stumbles-gusto-goes-head-on-by-selling-insurance'

;(async () => {
  const { body: html, url } = await got(targetUrl)
  const metadata = await metascraper({ html, url })
  console.log(metadata)
})()

The output will be something like:

{
  "author": "Ellen Huet",
  "date": "2016-05-24T18:00:03.894Z",
  "description": "The HR startups go to war.",
  "image": "https://assets.bwbx.io/images/users/iqjWHBFdfxIU/ioh_yWEn8gHo/v1/-1x-1.jpg",
  "publisher": "Bloomberg.com",
  "title": "As Zenefits Stumbles, Gusto Goes Head-On by Selling Insurance",
  "url": "http://www.bloomberg.com/news/articles/2016-05-24/as-zenefits-stumbles-gusto-goes-head-on-by-selling-insurance"
}

Metadata

?> Other metadata can be defined using a custom rule bundle.

Here is an example of the metadata that metascraper can collect:

How It Works

metascraper is built out of rules bundles.

It was designed to be easy to adapt. You can compose your own transformation pipeline using existing rules or write your own.

Rules bundles are a collection of HTML selectors around a determinate property. When you load the library, implicitly it is loading core rules.

Each set of rules load a set of selectors in order to get a determinate value.

These rules are sorted with priority: The first rule that resolve the value successfully, stop the rest of rules for get the property. Rules are sorted intentionally from specific to more generic.

Rules work as fallback between them:

  • If the first rule fails, then it fallback in the second rule.
  • If the second rule fails, time to third rule.
  • etc

metascraper do that until finish all the rule or find the first rule that resolves the value.

Importing Rules

metascraper exports a constructor that need to be initialized providing a collection of rules to load:

const metascraper = require('metascraper')([
  require('metascraper-author')(),
  require('metascraper-date')(),
  require('metascraper-description')(),
  require('metascraper-image')(),
  require('metascraper-logo')(),
  require('metascraper-clearbit')(),
  require('metascraper-publisher')(),
  require('metascraper-title')(),
  require('metascraper-url')()
])

Again, the order of rules are loaded are important: Just the first rule that resolve the value will be applied.

Use the first parameter to pass custom options specific per each rules bundle:

const metascraper = require('metascraper')([
  require('metascraper-clearbit')({
    size: 256,
    format: 'jpg'
  })
])

Rules Bundles

?> Can't find the rules bundle that you want? Let's open an issue to create it.

Official

Rules bundles maintained by metascraper maintainers.

PackageVersionDependencies
metascraper-amazonnpmDependency Status
metascraper-audionpmDependency Status
metascraper-authornpmDependency Status
metascraper-clearbitnpmDependency Status
metascraper-datenpmDependency Status
metascraper-descriptionnpmDependency Status
@metascraper/helpersnpmDependency Status
metascraper-imagenpmDependency Status
metascraper-iframenpmDependency Status
metascraper-langnpmDependency Status
metascraper-logonpmDependency Status
metascraper-logo-faviconnpmDependency Status
metascraper-media-providernpmDependency Status
metascraper-publishernpmDependency Status
metascraper-readabilitynpmDependency Status
metascraper-soundcloudnpmDependency Status
metascraper-telegramnpmDependency Status
metascraper-titlenpmDependency Status
metascraper-uolnpmDependency Status
metascraper-urlnpmDependency Status
metascraper-spotifynpmDependency Status
metascraper-videonpmDependency Status
metascraper-youtubenpmDependency Status

Community

Rules bundles maintained by individual users.

Write Your Own Rules

See CONTRIBUTING.

API

constructor(rules)

Create a new metascraper instance declaring the rules bundle to be used explicitly.

rules

Type: Array

The collection of rules bundle to be loaded.

metascraper(options)

Call the instance for extracting content based on rules bundle provided at the constructor.

options

url

Required Type: String

The URL associated with the HTML markup.

It is used for resolve relative links that can be present in the HTML markup.

it can be used as fallback field for different rules as well.

html

Type: String

The HTML markup for extracting the content.

rules

Type: Array

You can pass additional rules to add on execution time.

These rules will be merged with your loaded rules at the beginning.

validateUrl

Type: boolean Default: true

Ensure the URL provided is validated as a WHATWG URL API compliant.

Benchmark

To give you an idea of how accurate metascraper is, here is a comparison of similar libraries:

Librarymetascraperhtml-metadatanode-metainspectoropen-graph-scraperunfluff
Correct95.54%74.56%61.16%66.52%70.90%
Incorrect1.79%1.79%0.89%6.70%10.27%
Missed2.68%23.67%37.95%26.34%8.95%

A big part of the reason for metascraper's higher accuracy is that it relies on a series of fallbacks for each piece of metadata, instead of just looking for the most commonly-used, spec-compliant pieces of metadata, like Open Graph.

metascraper's default settings are targetted specifically at parsing online articles, which is why it's able to be more highly-tuned than the other libraries for that purpose.

If you're interested in the breakdown by individual pieces of metadata, check out the full comparison summary, or dive into the raw result data for each library.

License

metascraper © Ian Storm Taylor, Released under the MIT License. Maintained by Kiko Beats with help from contributors.

5.45.0

2 months ago

5.43.7

3 months ago

5.44.0

3 months ago

5.43.4

3 months ago

5.43.3

4 months ago

5.43.1

4 months ago

5.43.0

4 months ago

5.42.5

4 months ago

5.42.2

5 months ago

5.42.0

5 months ago

5.40.0

5 months ago

5.39.0

5 months ago

5.37.1

8 months ago

5.38.0

6 months ago

5.34.9

10 months ago

5.34.6

11 months ago

5.34.7

11 months ago

5.34.10

9 months ago

5.35.1

9 months ago

5.35.2

9 months ago

5.35.0

9 months ago

5.36.0

9 months ago

5.34.3

1 year ago

5.34.4

1 year ago

5.34.2

1 year ago

5.34.1

1 year ago

5.33.7

1 year ago

5.33.5

1 year ago

5.33.4

1 year ago

5.31.3

1 year ago

5.31.2

1 year ago

5.32.4

1 year ago

5.32.3

1 year ago

5.32.1

1 year ago

5.33.3

1 year ago

5.30.4

2 years ago

5.30.3

2 years ago

5.31.1

2 years ago

5.30.2

2 years ago

5.30.1

2 years ago

5.29.7

2 years ago

5.29.6

2 years ago

5.29.5

2 years ago

5.29.15

2 years ago

5.29.14

2 years ago

5.29.13

2 years ago

5.29.11

2 years ago

5.29.10

2 years ago

5.28.9

2 years ago

5.28.5

2 years ago

5.28.2

2 years ago

5.29.3

2 years ago

5.29.1

2 years ago

5.29.0

2 years ago

5.26.3

2 years ago

5.26.0

2 years ago

5.25.8

2 years ago

5.25.7

2 years ago

5.25.6

2 years ago

5.25.5

2 years ago

5.25.4

2 years ago

5.25.2

2 years ago

5.25.1

2 years ago

5.25.0

3 years ago

5.24.9

3 years ago

5.24.8

3 years ago

5.24.7

3 years ago

5.24.6

3 years ago

5.24.2

3 years ago

5.24.1

3 years ago

5.24.0

3 years ago

5.23.3

3 years ago

5.23.2

3 years ago

5.23.1

3 years ago

5.23.0

3 years ago

5.22.11

3 years ago

5.22.9

3 years ago

5.22.8

3 years ago

5.22.7

3 years ago

5.22.5

3 years ago

5.22.4

3 years ago

5.22.2

3 years ago

5.22.1

3 years ago

5.22.0

3 years ago

5.21.9

3 years ago

5.21.8

3 years ago

5.21.7

3 years ago

5.21.6

3 years ago

5.21.10

3 years ago

5.21.5

3 years ago

5.21.4

3 years ago

5.21.3

3 years ago

5.21.2

3 years ago

5.20.0

3 years ago

5.21.0

3 years ago

5.19.0

3 years ago

5.18.12

3 years ago

5.18.10

3 years ago

5.18.9

3 years ago

5.18.6

3 years ago

5.18.5

3 years ago

5.18.4

3 years ago

5.18.3

3 years ago

5.18.2

3 years ago

5.18.1

3 years ago

5.18.0

3 years ago

5.17.0

3 years ago

5.16.16

3 years ago

5.16.15

3 years ago

5.16.14

3 years ago

5.16.13

3 years ago

5.16.11

3 years ago

5.16.9

3 years ago

5.16.7

3 years ago

5.16.6

3 years ago

5.16.5

3 years ago

5.16.3

3 years ago

5.16.0

3 years ago

5.15.4

3 years ago

5.15.3

3 years ago

5.15.0

3 years ago

5.14.26

3 years ago

5.14.25

3 years ago

5.14.24

3 years ago

5.14.23

3 years ago

5.14.22

3 years ago

5.14.21

3 years ago

5.14.20

4 years ago

5.14.18

4 years ago

5.14.17

4 years ago

5.14.16

4 years ago

5.14.15

4 years ago

5.14.14

4 years ago

5.14.12

4 years ago

5.14.11

4 years ago

5.14.7

4 years ago

5.14.5

4 years ago

5.14.4

4 years ago

5.14.3

4 years ago

5.14.2

4 years ago

5.14.1

4 years ago

5.13.2

4 years ago

5.13.1

4 years ago

5.12.19

4 years ago

5.12.18

4 years ago

5.12.15

4 years ago

5.12.16

4 years ago

5.12.17

4 years ago

5.12.14

4 years ago

5.12.9

4 years ago

5.12.7

4 years ago

5.12.5

4 years ago

5.12.3

4 years ago

5.12.1

4 years ago

5.12.0

4 years ago

5.11.21

4 years ago

5.11.20

4 years ago

5.11.16

4 years ago

5.11.15

4 years ago

5.11.14

4 years ago

5.11.13

4 years ago

5.11.10

4 years ago

5.11.9

4 years ago

5.11.8

4 years ago

5.11.7

4 years ago

5.11.6

4 years ago

5.11.5

4 years ago

5.11.4

4 years ago

5.11.2

4 years ago

5.11.1

4 years ago

5.10.7

4 years ago

5.10.6

4 years ago

5.10.5

4 years ago

5.10.3

4 years ago

5.9.5

4 years ago

5.8.15

4 years ago

5.8.13

4 years ago

5.8.12

4 years ago

5.8.10

4 years ago

5.8.9

4 years ago

5.8.7

4 years ago

5.8.6

4 years ago

5.8.5

4 years ago

5.8.0

4 years ago

5.7.21

4 years ago

5.7.17

5 years ago

5.7.14

5 years ago

5.7.7

5 years ago

5.7.6

5 years ago

5.7.5

5 years ago

5.7.4

5 years ago

5.7.1

5 years ago

5.7.0

5 years ago

5.6.7

5 years ago

5.6.6

5 years ago

5.6.5

5 years ago

5.6.4

5 years ago

5.6.3

5 years ago

5.6.2

5 years ago

5.6.1

5 years ago

5.6.0

5 years ago

5.5.4

5 years ago

5.5.3

5 years ago

5.5.1

5 years ago

5.5.0

5 years ago

5.4.7

5 years ago

5.3.0

5 years ago