Gathering detailed insights and metrics for @us3r-network/metadata-scraper
Gathering detailed insights and metrics for @us3r-network/metadata-scraper
npm install @us3r-network/metadata-scraper
Typescript
Module System
Node Version
NPM Version
70.4
Supply Chain
98.9
Quality
83.5
Maintenance
100
Vulnerability
100
License
TypeScript (97.77%)
JavaScript (2.23%)
Total Downloads
1,970
Last Day
3
Last Week
9
Last Month
13
Last Year
1,613
114 Stars
414 Commits
18 Forks
4 Watching
6 Branches
4 Contributors
Minified
Minified + Gzipped
Latest Version
0.3.3
Package Id
@us3r-network/metadata-scraper@0.3.3
Unpacked Size
46.24 kB
Size
9.11 kB
File Count
11
NPM Version
10.2.3
Node Version
20.10.0
Publised On
03 Feb 2024
Cumulative downloads
Total Downloads
Last day
50%
3
Compared to previous day
Last week
200%
9
Compared to previous week
Last month
-23.5%
13
Compared to previous month
Last year
351.8%
1,613
Compared to previous year
metadata-scraper is a Javascript library which scrapes/parses metadata from web pages. You only need to supply it with a URL or an HTML string and it will use different rules to find the most relevant metadata like:
Install metadata-scraper via npm:
1npm install metadata-scraper
Import metadata-scraper
and pass it a URL or options object:
1const getMetaData = require('metadata-scraper') 2 3const url = 'https://github.com/BetaHuhn/metadata-scraper' 4 5getMetaData(url).then((data) => { 6 console.log(data) 7})
Or with async
/await
:
1const getMetaData = require('metadata-scraper') 2 3async function run() { 4 const url = 'https://github.com/BetaHuhn/metadata-scraper' 5 const data = await getMetaData(url) 6 console.log(data) 7} 8 9run()
This will return:
1{ 2 title: 'BetaHuhn/metadata-scraper', 3 description: 'A Javascript library for scraping/parsing metadata from a web page.', 4 language: 'en', 5 url: 'https://github.com/BetaHuhn/metadata-scraper', 6 provider: 'GitHub', 7 twitter: '@github', 8 image: 'https://avatars1.githubusercontent.com/u/51766171?s=400&v=4', 9 icon: 'https://github.githubassets.com/favicons/favicon.svg' 10}
You can see a list of all metadata which metadata-scraper tries to scrape below.
You can change the behaviour of metadata-scraper by passing an options object:
1const getMetaData = require('metadata-scraper') 2 3const options = { 4 url: 'https://github.com/BetaHuhn/metadata-scraper', // URL of web page 5 maxRedirects: 0, // Maximum number of redirects to follow (default: 5) 6 ua: 'MyApp', // Specify User-Agent header 7 lang: 'de-CH', // Specify Accept-Language header 8 timeout: 1000, // Request timeout in milliseconds (default: 10000ms) 9 forceImageHttps: false, // Force all image URLs to use https (default: true) 10 customRules: {} // more info below 11} 12 13getMetaData(options).then((data) => { 14 console.log(data) 15})
You can specify the URL by either passing it as the first parameter, or by setting it in the options object.
Here are some examples on how to use metadata-scraper:
Pass a URL as the first parameter and metadata-scraper automatically scrapes it and returns everything it finds:
1const getMetaData = require('metadata-scraper') 2const data = await getMetaData('https://github.com/BetaHuhn/metadata-scraper')
Example file located at examples/basic.js.
If you already have an HTML string and don't want metadata-scraper to make an http request, specify it in the options object:
1const getMetaData = require('metadata-scraper') 2 3const html = ` 4 <meta name="og:title" content="Example"> 5 <meta name="og:description" content="This is an example."> 6` 7 8const options { 9 html: html, 10 url: 'https://example.com' // Optional URL to make relative image paths absolute 11} 12 13const data = await getMetaData(options)
Example file located at examples/html.js.
Look at the rules.ts
file in the src
directory to see all rules which will be used.
You can expand metadata-scraper easily by specifying custom rules:
1const getMetaData = require('metadata-scraper') 2 3const options = { 4 url: 'https://github.com/BetaHuhn/metadata-scraper', 5 customRules: { 6 name: { 7 rules: [ 8 [ 'meta[name="customName"][content]', (element) => element.getAttribute('content') ] 9 ], 10 processor: (text) => text.toLowerCase() 11 } 12 } 13} 14 15const data = await getMetaData(options)
customRules
needs to contain one or more objects, where the key (name above) will identify the value in the returned data.
You can then specify different rules for each item in the rules array.
The first item is the query which gets inserted into the browsers querySelector function, and the second item is a function which gets passed the HTML element:
1[ 'querySelector', (element) => element.innerText ]
You can also specify a processor
function which will process/transform the result of one of the matched rules:
1{ 2 processor: (text) => text.toLowerCase() 3}
If you find a useful rule, let me know and I will add it (or create a PR yourself).
Example file located at examples/custom.js.
Here's what metadata-scraper currently tries to scrape:
1{ 2 title: 'Title of page or article', 3 description: 'Description of page or article', 4 language: 'Language of page or article', 5 type: 'Page type', 6 url: 'URL of page', 7 provider: 'Page provider', 8 keywords: ['array', 'of', 'keywords'], 9 section: 'Section/Category of page', 10 author: 'Article author', 11 published: 1605221765, // Date the article was published 12 modified: 1605221765, // Date the article was modified 13 robots: ['array', 'for', 'robots'], 14 copyright: 'Page copyright', 15 email: 'Contact email', 16 twitter: 'Twitter handle', 17 facebook: 'Facebook account id', 18 image: 'Image URL', 19 icon: 'Favicon URL', 20 video: 'Video URL', 21 audio: 'Audio URL' 22}
If you find a useful metatag, let me know and I will add it (or create a PR yourself).
Issues and PRs are very welcome!
Please check out the contributing guide before you start.
This project adheres to Semantic Versioning. To see differences with previous versions refer to the CHANGELOG.
This library was developed by me (@betahuhn) in my free time. If you want to support me:
This library is based on Mozilla's page-metadata-parser. I converted it to TypeScript, implemented a few new features, and added more rules.
Copyright 2020 Maximilian Schiller
This project is licensed under the MIT License - see the LICENSE file for details.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/16 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
34 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More