Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #42 from jhurliman/master

Gracefully handle webpages that cannot be parsed with jsdom/jQuery
  • Loading branch information...
commit b26a86cce3224076e0a3201b066c9d6b179b8eac 2 parents 1a9bab5 + dbdecf1
@chriso authored
Showing with 11 additions and 5 deletions.
  1. +11 −5 lib/node.io/dom.js
View
16 lib/node.io/dom.js
@@ -50,12 +50,18 @@ Job.prototype.parseHtml = function (data, callback, response) {
ProcessExternalResources: this.options.external_resources,
QuerySelector: false
};
- var $, window = require('jsdom').jsdom(data, null, {features:features}).createWindow(),
- jquery = require('jquery')
+ var $, window, jquery, default_$;
+ try {
+ window = require('jsdom').jsdom(data, null, {features:features}).createWindow();
+ jquery = require('jquery');
default_$ = jquery.create(window);
- $ = function (selector, context) {
- return context ? jquery.create(context)(selector) : default_$(selector);
- };
+ $ = function (selector, context) {
+ return context ? jquery.create(context)(selector) : default_$(selector);
+ };
+ } catch (e) {
+ callback.apply(self, [e, $, data, headers, response]);
+ return;
+ }
if (recurse === 1 || recurse === true || recurse instanceof Array) {
this.recurseUrls($);
}
Please sign in to comment.
Something went wrong with that request. Please try again.