Permalink
Browse files

Fixing for new node and jsdom.

  • Loading branch information...
1 parent 7097a08 commit ce70f1ff2ef371461e5978af21877b4230c7e7b5 @mikeal committed Mar 10, 2012
Showing with 15 additions and 36 deletions.
  1. +12 −33 main.js
  2. +3 −3 package.json
View
45 main.js
@@ -2,6 +2,7 @@ var request = require('request')
, fs = require('fs')
, sys = require('sys')
, path = require('path')
+ , vm = require('vm')
, jsdom = require('jsdom')
, util = require('util')
, urlParse = require('url').parse
@@ -40,33 +41,6 @@ jsdom.defaultDocumentFeatures =
, MutationEvents : false
, QuerySelector : false
}
-
-var Context = process.binding('evals').Context,
- Script = process.binding('evals').Script;
-jqueryify = function(window, document) {
- var filename = jqueryFilename
- , document = window.document
- ;
- if (window) {
- var ctx = window.__scriptContext;
- if (!ctx) {
- window.__scriptContext = ctx = new Context();
- ctx.__proto__ = window;
- }
- var tracelimitbak = Error.stackTraceLimit;
- Error.stackTraceLimit = 100;
- try {
- Script.runInContext(jquery, ctx, filename);
- }
- catch(e) {
- document.trigger(
- 'error', 'Running ' + filename + ' failed.',
- {error: e, filename: filename}
- );
- }
- Error.stackTraceLimit = tracelimitbak;
- }
-};
var debug = 1
, info = 50
@@ -167,7 +141,8 @@ Spider.prototype.get = function (url, referer) {
return;
}
if (resp.headers['set-cookie']) {
- self.jar.setCookies(resp.headers['set-cookie'])
+ try { self.jar.setCookies(resp.headers['set-cookie']) }
+ catch(e) {}
}
self.cache.set(url, resp.headers, body);
self._handler(url, referer, {fromCache:false, headers:resp.headers, body:body});
@@ -195,8 +170,12 @@ Spider.prototype._handler = function (url, referer, response) {
r.spider = this;
r.response = response
r.url = u;
- var window = jsdom.jsdom(response.body).createWindow();
- jqueryify(window);
+ console.error('test1')
+
+ var document = jsdom.jsdom(response.body, null, {})
+ var window = document.createWindow()
+ window.run(jquery, jqueryFilename)
+
window.$.fn.spider = function () {
this.each(function () {
var h = window.$(this).attr('href');
@@ -206,15 +185,15 @@ Spider.prototype._handler = function (url, referer, response) {
self.get(h, url);
})
}
-
+
this.currentUrl = url;
if (jsdom.defaultDocumentFeatures.ProcessExternalResources) {
$(function () { r.fn.call(r, window, window.$); })
} else {
r.fn.call(r, window, window.$);
}
- this.currentUrl = null;
- }
+ this.currentUrl = null;
+ }
}
Spider.prototype.log = function (level) {
if (typeof level === 'string') level = logLevels[level];
View
6 package.json
@@ -1,19 +1,19 @@
{ "name" : "spider"
, "description" : "Programmable spidering of web sites with node.js and jQuery"
, "tags" : ["dom","javascript","crawling","jquery", "spider", "spidering"]
-, "version" : "0.0.2"
+, "version" : "0.1.0"
, "author" : "Mikeal Rogers <mikeal.rogers@gmail.com>"
, "repository" :
{ "type" : "git"
, "url" : "http://github.com/mikeal/spider.git"
}
, "bugs" :
{ "web" : "http://github.com/mikeal/spider/issues" }
-, "engines" : ["node >= 0.4.4"]
+, "engines" : ["node >= 0.6.4"]
, "main" : "./main"
, "dependencies":
{ "request" : ">= 1.9.3"
- , "jsdom" : ">= 0.2.0"
+ , "jsdom" : ">= 0.2.13"
, "routes" : ">= 0.1.0"
, "cookiejar": ">= 1.3.0"
}

0 comments on commit ce70f1f

Please sign in to comment.