JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 42293
  • Score
    100M100P100Q148892F

Wicked Good XPath

Package Exports

  • wgxpath

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wgxpath) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-wgxpath

Wicked Good XPath is a fast implementation of document.createEvaluation and document.evaluate (DOM3-XPath) in pure Javascript.

Version

I'm pretty lazy, so I didn't build Wicked Good XPath myself. When the pre-compiled wgxpath.install.js is updated, I'll update this package.

0.x.y: x refers to the Google SVN revision when wgxpath.install.js was built, and any improvements to this library will be indicated by y.

Installation

Install with npm:

npm install wgxpath

Example

This example scrapes the Merriam-Webster Word of the Day. This code can also be found in the included word_of_the_day.js.

var wgxpath = require('wgxpath');
var jsdom = require('jsdom');

var url = 'http://www.merriam-webster.com/word-of-the-day/';
var expressionString = '//*[@id="content"]/div[3]/ul/li[1]/strong';

jsdom.env({
  html: url,
  done: function(errors, window) {
    wgxpath.install(window);
    var expression = window.document.createExpression(expressionString);
    var result = expression.evaluate(window.document,
        wgxpath.XPathResultType.STRING_TYPE);
    console.log('The Word of the Day is "' + result.stringValue + '."');
  }
});