metadata-crawler
This is a simple node.js module for scraping meta information from web pages.
At the moment this module supports:
- the
<title>
tag in the document head
- meta[name="description"] tag
- link[rel="canonical"] tag
- img elements on the page
- many Open Graph tags (such as: title, description, url, type, image, video)
Install
npm install metatag-crawler --save
Usage
var scrape = require('metatag-crawler');
scrape('https://www.youtube.com/watch?v=jNQXAC9IVRw', function(err, data) {});
// if you do not want the relative URLs to be resolved
scrape('https://www.youtube.com/watch?v=jNQXAC9IVRw', { resolveUrls: false }, function(err, data) {});
Example
var scrape = require('metatag-crawler');
scrape('https://www.youtube.com/watch?v=jNQXAC9IVRw', function(err, data) {
console.log(err);
console.log(data.meta.title);
console.log(data.meta.description);
console.log(data.meta.canonical);
console.log(data);
});
Changes in version 2.x
In version 2 the module does not automatically merge properties from different meta information sources.
Earlier we used to the the following: title = opengpraph.title || meta.title
and so on with description and canonical url.
This is no longer the case, we provide all information available on the page. If you need the old behavior, please process the result like this:
scrape('https://www.youtube.com/watch?v=jNQXAC9IVRw', function(err, data) {
var oldStyleData = {
title: data.og.title || data.meta.title,
description: data.og.descriptions || data.meta.description,
images: og.images,
videos: og.videos
};
});