Miss any of our Open RFC calls?Watch the recordings here! »

sitemapper

3.1.10 • Public • Published

Sitemap-parser

Build Status Monthly Downloads npm version GitHub license Inline docs GitHub Release Date Codecov Libraries.io dependency status for latest release LGTM Alerts LGTM Grade Test

Parse through a sitemaps xml to get all the urls for your crawler.

Version 2

Installation

npm install sitemapper --save

Simple Example

const Sitemapper = require('sitemapper');
 
const sitemap = new Sitemapper();
 
sitemap.fetch('https://wp.seantburke.com/sitemap.xml').then(function(sites) {
  console.log(sites);
});
 

Examples in ES6

import Sitemapper from 'sitemapper';
 
(async () => {
  const Google = new Sitemapper({
    url: 'https://www.google.com/work/sitemap.xml',
    timeout: 15000, // 15 seconds
  });
 
  try {
    const { sites } = await Google.fetch();
    console.log(sites);
  catch (error) {
    console.log(error);
  }
})();
 
// or
 
const sitemapper = new Sitemapper();
sitemapper.timeout = 5000;
 
sitemapper.fetch('https://wp.seantburke.com/sitemap.xml')
  .then(({ url, sites }) => console.log(`url:${url}`, 'sites:', sites))
  .catch(error => console.log(error));

Options

You can add options on the initial Sitemapper object when instantiating it.

  • requestHeaders: (Object) - Additional Request Headers
  • timeout: (Number) - Maximum timeout for a single URL
 
const sitemapper = new Sitemapper({
  url: 'https://art-works.community/sitemap.xml',
  timeout: 15000,
  requestHeaders: {
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0'
  }
});
 

Examples in ES5

var Sitemapper = require('sitemapper');
 
var Google = new Sitemapper({
  url: 'https://www.google.com/work/sitemap.xml',
  timeout: 15000 //15 seconds
});
 
Google.fetch()
  .then(function (data) {
    console.log(data);
  })
  .catch(function (error) {
    console.log(error);
  });
 
 
// or
 
 
var sitemapper = new Sitemapper();
 
sitemapper.timeout = 5000;
sitemapper.fetch('https://wp.seantburke.com/sitemap.xml')
  .then(function (data) {
    console.log(data);
  })
  .catch(function (error) {
    console.log(error);
  });
 

Version 1

npm install sitemapper@1.1.1 --save

Simple Example

var Sitemapper = require('sitemapper');
 
var sitemapper = new Sitemapper();
 
sitemapper.getSites('https://wp.seantburke.com/sitemap.xml', function(err, sites) {
    if (!err) {
     console.log(sites);
    }
});

Install

npm i sitemapper

DownloadsWeekly Downloads

2,670

Version

3.1.10

License

MIT

Unpacked Size

11.9 kB

Total Files

7

Last publish

Collaborators

  • avatar