Comparing version 0.3.4 to 0.3.5
@@ -17,3 +17,3 @@ var read = require('../'); | ||
} | ||
}, function(err, art){ | ||
}, function(err, art, options, resp){ | ||
if (err) { | ||
@@ -20,0 +20,0 @@ console.log('[ERROR]', err.message); |
@@ -0,1 +1,4 @@ | ||
# 2015/06/03 | ||
- Add response data to callback arguments | ||
# 2015/03/10 | ||
@@ -2,0 +5,0 @@ - Remove empty content in JSON output mode |
@@ -61,3 +61,4 @@ "use strict"; | ||
parsingData.html = resp.body.toString(); | ||
parse(parsingData); | ||
delete resp.body; | ||
parse(parsingData, resp); | ||
}); | ||
@@ -78,5 +79,6 @@ } else { | ||
* @param o options | ||
* @param e extra data | ||
* @return {String} | ||
*/ | ||
function parse(o){ | ||
function parse(o, e){ | ||
if (!o.html) { | ||
@@ -98,3 +100,3 @@ return ''; | ||
var $ = cheerio.load(o.html, co); | ||
o.callback(null, new Article($, o.options), o.options); | ||
o.callback(null, new Article($, o.options), o.options, e); | ||
} |
{ | ||
"name": "read-art", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "Scrape/Crawl article from any site automatically. Make any web page readable, no matter Chinese or English.", | ||
@@ -32,4 +32,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"cheerio": "~0.18.0", | ||
"req-fast": "^0.2.7", | ||
"cheerio": "~0.19.0", | ||
"req-fast": "^0.2.8", | ||
"URIjs": "^1.14.0", | ||
@@ -36,0 +36,0 @@ "entities": "~1.1.1" |
@@ -72,3 +72,7 @@ read-art [](http://badge.fury.io/js/read-art) [](https://travis-ci.org/Tjatse/node-readability) | ||
- **node** The [cheerio object](https://github.com/cheeriojs/cheerio#selectors). | ||
* **callback** The callback to run - `callback(error, article, options)` | ||
* **callback** The callback to run - `callback(error, article, options, response)`, arguments are: | ||
- **error** `Error` object when exception has been caught. | ||
- **article** The article object, including: `article.title`, `article.content` and `article.html`. | ||
- **options** The request options. | ||
- **response** The response of your request, including: `response.headers`, `response.redirects`, `response.cookies` and `response.statusCode`. | ||
@@ -82,3 +86,3 @@ > Head over to test or examples directory for a complete example. | ||
// read from google: | ||
read('http://google.com', function(err, art, options){ | ||
read('http://google.com', function(err, art, options, resp){ | ||
if(err){ | ||
@@ -90,2 +94,4 @@ throw err; | ||
html = art.html; // whole original innerHTML | ||
console.log('[STATUS CODE]', resp && resp.statusCode); | ||
}); | ||
@@ -96,7 +102,7 @@ // or: | ||
charset: 'utf8' | ||
}, function(err, art, options){ | ||
}, function(err, art, options, resp){ | ||
}); | ||
// what about html? | ||
read('<title>node-art</title><body><div><p>hello, read-art!</p></div></body>', function(err, art, options){ | ||
read('<title>node-art</title><body><div><p>hello, read-art!</p></div></body>', function(err, art, options, resp){ | ||
@@ -107,3 +113,3 @@ }); | ||
uri: '<title>node-art</title><body><div><p>hello, read-art!</p></div></body>' | ||
}, function(err, art, options){ | ||
}, function(err, art, options, resp){ | ||
@@ -110,0 +116,0 @@ }); |
@@ -10,3 +10,12 @@ var read = require('../'), | ||
it('should have title & content',function(done){ | ||
read('http://www.theatlantic.com/international/archive/2014/05/the-last-man-at-nuremberg/361968/', function(err, art){ | ||
read({ | ||
uri: 'http://www.theatlantic.com/international/archive/2014/05/the-last-man-at-nuremberg/361968/', | ||
scoreRule: function(node){ | ||
var id = node.attr('id'); | ||
if (id == 'article-section-1') { | ||
return 100 | ||
} | ||
return 0; | ||
} | ||
}, function(err, art){ | ||
should.not.exist(err); | ||
@@ -13,0 +22,0 @@ expect(art).to.be.an('object'); |
@@ -11,3 +11,3 @@ | ||
before(function(){ | ||
uri = 'http://bing.com'; | ||
uri = 'http://www.bing.com'; | ||
html = '<p>Hello, node-art</p>'; | ||
@@ -23,6 +23,7 @@ charset = 'utf8'; | ||
it('should detect two options',function(done){ | ||
read(uri, { charset: charset }, function(err, art, options){ | ||
read(uri, { charset: charset }, function(err, art, options, resp){ | ||
should.not.exist(err); | ||
options.uri.should.be.equal(uri); | ||
options.charset.should.be.equal(charset); | ||
resp.statusCode.should.be.equal(200) | ||
done(); | ||
@@ -29,0 +30,0 @@ }); |
55834
1334
372
+ Addedboolbase@1.0.0(transitive)
+ Addedcheerio@0.19.0(transitive)
+ Addedcss-select@1.0.0(transitive)
+ Addedcss-what@1.0.0(transitive)
+ Addeddom-serializer@0.1.1(transitive)
+ Addeddomelementtype@1.3.1(transitive)
+ Addedlodash@3.10.1(transitive)
+ Addednth-check@1.0.2(transitive)
- RemovedCSSselect@0.4.1(transitive)
- RemovedCSSwhat@0.4.7(transitive)
- Removedcheerio@0.18.0(transitive)
- Removeddom-serializer@0.0.1(transitive)
- Removeddomelementtype@1.1.3(transitive)
- Removedlodash@2.4.2(transitive)
Updatedcheerio@~0.19.0
Updatedreq-fast@^0.2.8