Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

changed directory layout

  • Loading branch information...
commit 8161b261a3b1b62a728e063ca39b331aed58407f 1 parent 82c7bf8
@dachev authored
View
73 examples/web.js
@@ -0,0 +1,73 @@
+#!/usr/bin/env node
+
+var http = require('http'),
+ fs = require('fs'),
+ events = require('events'),
+ inherits = require('sys').inherits,
+ dominiq = require('../lib/dominiq'),
+ sizzFact = require('../lib/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);
+
+/*
+function FileClient(path) {
+ var self = this;
+
+ fs.readFile(path, 'utf8', function (err, html) {
+ if (err) {
+ self.emit('done', err, '');
+ }
+ else {
+ self.emit('done', 200, html);
+ }
+ });
+}
+inherits(FileClient, 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]);
+ }
+});
+
+
+
+
+
+
+
View
2  test.js
@@ -2,7 +2,7 @@
require.paths.push(__dirname);
require.paths.push(__dirname + '/lib');
-require.paths.push(__dirname + '/deps/nodeunit');
+require.paths.push(__dirname + '/test/nodeunit');
try {
var testrunner = require('nodeunit').testrunner;
View
0  deps/nodeunit/nodeunit.js → test/nodeunit/nodeunit.js
File renamed without changes
View
0  deps/nodeunit/testrunner.js → test/nodeunit/testrunner.js
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.