Comparing version 0.2.2 to 0.2.3
@@ -30,5 +30,5 @@ var u2r = require('u2r'); | ||
var $j = new Junjo().noTimeout(); | ||
var $J = new Junjo.Template({noTimeout : true}); | ||
$j.inputs({ | ||
$J.inputs({ | ||
url : 0, | ||
@@ -38,7 +38,7 @@ options : 1 | ||
$j.start(function(url, options) { | ||
$J.start(function(url, options) { | ||
this.$.debug = options.debug; | ||
}); | ||
$j('header', function(options) { | ||
$J('header', function(options) { | ||
options || (options = {}); | ||
@@ -63,3 +63,3 @@ var header = (!options || !options.header) ? {} : options.header; | ||
$j('request', function(url, header, options) { | ||
$J('request', function(url, header, options) { | ||
var ops = u2r(url, options); | ||
@@ -117,3 +117,3 @@ if (ops.method == "POST") { | ||
$j('contentType', function(contentType) { | ||
$J('contentType', function(contentType) { | ||
var vals = contentType.split("; charset="); | ||
@@ -134,3 +134,3 @@ contentType = vals[0]; | ||
$j('resultStream', function(res, contentType, charset, options) { | ||
$J('resultStream', function(res, contentType, charset, options) { | ||
charset = options.charset || charset; | ||
@@ -167,3 +167,2 @@ var stream; | ||
this.out['result'] = (this.text) ? out.toString() : out; | ||
}) | ||
@@ -173,20 +172,20 @@ .after('request', 'contentType', 'options'); | ||
return function browse(url, options, callback) { | ||
return (url) ? $j.clone().exec(url, options, callback) : $j.clone(); | ||
return (url) ? new $J().exec(url, options, callback) : new $J(); | ||
}; | ||
})(); | ||
var jbrowser = (function() { | ||
var $b = new Junjo(); | ||
$b.start(function(cookieManager) { | ||
var browser = (function() { | ||
var $B = new Junjo.Template(); | ||
$B.start(function(cookieManager) { | ||
this.$.cookieManager= cookieManager || new CookieManager(); | ||
}); | ||
$b("agent", function() { return "" }); | ||
$B("agent", function() { return "" }); | ||
return function jbrowser(url, options, callback) { | ||
var $ret = $b.clone(); | ||
return function browser(url, options, callback) { | ||
var $ret = new ($B.clone()); | ||
options || (options = {}); | ||
Object.keys(jbrowser.prototype).forEach(function(name) { | ||
$ret[name] = jbrowser.prototype[name]; | ||
Object.keys(browser.prototype).forEach(function(name) { | ||
$ret[name] = browser.prototype[name]; | ||
}); | ||
$ret.noTimeout(); | ||
$ret.noTimeout(true); | ||
$ret.count = 0; | ||
@@ -197,3 +196,3 @@ var mR = parseInt(options.maxRedirect), rC = parseInt(options.redirectCount); | ||
if (this instanceof jbrowser) return $ret; | ||
if (this instanceof browser) return $ret; | ||
$ret.browse(url, options); | ||
@@ -214,3 +213,3 @@ return $ret.exec(callback); | ||
**/ | ||
jbrowser.prototype.submit = function() { | ||
browser.prototype.submit = function() { | ||
var label = (arguments.length > 1) ? Array.prototype.shift.call(arguments) : undefined; | ||
@@ -250,3 +249,3 @@ var options = arguments[0]; | ||
jbrowser.prototype.browse = function() { | ||
browser.prototype.browse = function() { | ||
var count = ++this.count; | ||
@@ -336,3 +335,3 @@ var firstlbl = "url_options" + count; | ||
} | ||
var $jb = new jbrowser(); | ||
var $jb = new browser(); | ||
$jb.maxRedirect = $b.maxRedirect; | ||
@@ -361,3 +360,3 @@ $jb.redirectCount = ++$b.redirectCount; | ||
module.exports = jbrowser; | ||
module.exports = browser; | ||
module.exports.Junjo = Junjo; | ||
@@ -367,3 +366,3 @@ module.exports.browse = function() { | ||
var cb = Array.prototype.pop.call(arguments); | ||
var $b = new jbrowser().noTimeout(); | ||
var $b = new browser().noTimeout(true); | ||
$b.browse(url, arguments[0]); | ||
@@ -370,0 +369,0 @@ if (typeof cb != "function") cb = function() {}; |
{ | ||
"name": "browser" | ||
, "version": "0.2.2" | ||
, "version": "0.2.3" | ||
, "description": "browsing urls with cookies, that is, we can scrape with authenticated pages!" | ||
@@ -19,3 +19,3 @@ , "tags": ["scraping", "browse", "url", "cookie", "crawling", "login", "sign-in"] | ||
, "dependencies": | ||
{ "junjo": ">=0.1.0" | ||
{ "junjo": ">=0.2.0" | ||
, "termcolor" : "x.x.x" | ||
@@ -22,0 +22,0 @@ , "u2r" : "x.x.x" |
@@ -9,3 +9,2 @@ var browser = require('browser'); | ||
var server = http.createServer(function(req, res) { | ||
@@ -21,3 +20,2 @@ s.host(req, res, function(err, result) { | ||
$b = new browser(); | ||
$b.browse("euc", eucURL, {charset: "euc-jp"}); | ||
@@ -24,0 +22,0 @@ |
@@ -13,3 +13,4 @@ var browser = require("browser"); | ||
PersistentCookie : "yes" | ||
} | ||
}, | ||
debug : true | ||
}); | ||
@@ -19,2 +20,3 @@ $b.browse('https://mail.google.com/mail/u/0/?ui=html&zy=d').after(); | ||
$b.on("end", function(err, out) { | ||
console.log(out.result); | ||
T.ok(out.result.match("logout"), "has logined"); | ||
@@ -21,0 +23,0 @@ }); |
22705
13
477
Updatedjunjo@>=0.2.0