Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-sizzle

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-sizzle

Sizzle powered selectors for libxmljs

  • 0.1.0
  • latest
  • npm
  • Socket score

Maintainers
0
Created
Source

node-sizzle

A node.js plugin that brings sizzle and libxmljs together. Currently it passes all relevant sizzle tests when used with an HTML document.

Requirements

  • Node v0.1.102+
  • libxmljs v0.4.0+

How to install

npm install node-sizzle

How to test

To run the tests, go to the project's root directory and run node test.js

Demo

To run the tests, go to the examples directory and run node web.js

How to use

var http     = require('http'),
    events   = require('events'),
    inherits = require('sys').inherits,
    dominiq  = require('node-sizzle/dominiq'),
    sizzFact = require('node-sizzle');

function WebClient(host, path) {
    var self       = this,
        transport  = http.createClient(80, host),
        request    = transport.request('GET', path, {'host': host});
        
    request.end();
    
    request.on('response', function (response) {
        if (response.statusCode != 200) {
            self.emit('done', response.statusCode, '');
        }
        else {
            var html = '';
        
            response.setEncoding('utf8');
            response.on('data', function (chunk) {
                html += chunk;
            });
            response.on('end', function (chunk) {
                self.emit('done', 200, html);
            });
        }
    });
}
inherits(WebClient, events.EventEmitter);

var client = new WebClient('www.yahoo.com', '/');
client.on('done', function(status, html) {
    if (status != 200) {
        throw 'unable to download page';
    }

    var doc      = dominiq.createHTMLDocument(html),
        window   = {document:doc},
        sizzle   = sizzFact.sizzleInit(window),
        divs     = sizzle('div');

    for (var i = 0; i < divs.length; i++) {
        console.log(divs[i].toString());
    }
});

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc