cheerio-httpcli
Advanced tools
Comparing version 0.6.8 to 0.6.9
@@ -0,1 +1,7 @@ | ||
# 0.6.9 (2016-08-23) | ||
* 依存ライブラリを最新バージョンに更新 | ||
* Electron上で同期リクエストは未サポートのメッセージを表示するように変更 | ||
* POST後のリダイレクト先が相対パスの時にエラーになっていたのを修正(#15) | ||
# 0.6.8 (2016-04-12) | ||
@@ -2,0 +8,0 @@ |
@@ -304,3 +304,5 @@ /*eslint no-invalid-this:0*/ | ||
if (! $elem._root) { | ||
$elem._root = { 0: { _documentInfo: doc }}; | ||
$elem._root = { | ||
0: { _documentInfo: doc } | ||
}; | ||
} | ||
@@ -307,0 +309,0 @@ |
@@ -141,3 +141,3 @@ /*jshint -W100*/ | ||
if (/^30\d$/.test(res.statusCode) && res.headers.location) { | ||
return res.headers.location; | ||
return urlParser.resolve(res.request.uri.href, res.headers.location); | ||
} | ||
@@ -548,2 +548,8 @@ | ||
if (callback === 'sync') { | ||
// Electron上ではSync系メソッドはサポート外 | ||
// ※process.execPathで別スクリプトを実行する性質上 | ||
if (process.versions.electron) { | ||
throw new Error('sync request is not support on Electron'); | ||
} | ||
isSync = true; | ||
@@ -550,0 +556,0 @@ callback = null; |
{ | ||
"name": "cheerio-httpcli", | ||
"version": "0.6.8", | ||
"version": "0.6.9", | ||
"description": "http client module with cheerio & iconv(-lite) & promise", | ||
@@ -10,11 +10,11 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "node testrunner.js && true || true", | ||
"cov": "istanbul cover -x index.js -x testrunner.js testrunner.js -- -R nyan && true || true", | ||
"lint": "eslint lib test example --ext .js && true || true", | ||
"cs": "jscs lib test example && true || true", | ||
"dep": "depcheck --parsers=*.js:es6,*.json:json --ignores=iconv-lite,os-locale,espower-loader && true || true", | ||
"todo": "leasot -S lib/**/**/* test/** example/** && true || true" | ||
"test": "node testrunner.js || true", | ||
"cov": "istanbul cover -x index.js -x testrunner.js testrunner.js -- -R nyan || true", | ||
"lint": "eslint lib test example --ext .js || true", | ||
"cs": "jscs lib test example || true", | ||
"dep": "depcheck --parsers=*.js:es6,*.json:json --ignores=iconv-lite,os-locale,espower-loader || true", | ||
"todo": "leasot -S lib/**/**/* test/** example/** || true" | ||
}, | ||
"dependencies": { | ||
"async": "^2.0.0-rc.2", | ||
"async": "^2.0.1", | ||
"cheerio": "^0.20.0", | ||
@@ -24,13 +24,13 @@ "colors": "^1.1.2", | ||
"foreach": "^2.0.5", | ||
"he": "^1.0.0", | ||
"he": "^1.1.0", | ||
"iconv-lite": "^0.4.13", | ||
"jschardet": "^1.4.1", | ||
"object-assign": "^4.0.1", | ||
"object-assign": "^4.1.0", | ||
"os-locale": "^1.4.0", | ||
"prettyjson": "^1.1.3", | ||
"request": "^2.70.0", | ||
"request": "^2.74.0", | ||
"require-uncached": "^1.0.2", | ||
"rsvp": "^3.2.1", | ||
"spawn-sync": "^1.0.15", | ||
"tough-cookie": "^2.2.2", | ||
"tough-cookie": "^2.3.1", | ||
"type-of": "^2.0.1", | ||
@@ -41,16 +41,16 @@ "valid-url": "^1.0.9" | ||
"dev-null": "^0.1.1", | ||
"eslint": "^2.7.0", | ||
"espower-loader": "^1.0.0", | ||
"eslint": "^3.3.1", | ||
"espower-loader": "^1.0.1", | ||
"intelli-espower-loader": "^1.0.1", | ||
"isstream": "^0.1.2", | ||
"istanbul": "^0.4.3", | ||
"jscs": "^2.11.0", | ||
"istanbul": "^0.4.4", | ||
"jscs": "^3.0.7", | ||
"leasot": "^3.2.2", | ||
"mocha": "^2.4.5", | ||
"mocha": "^3.0.2", | ||
"mocha-clean": "^1.0.0", | ||
"node-static": "^0.7.7", | ||
"power-assert": "^1.3.1", | ||
"node-static": "^0.7.8", | ||
"power-assert": "^1.4.1", | ||
"random-string": "^0.1.2", | ||
"strip-ansi": "^3.0.1", | ||
"yargs": "^4.4.0" | ||
"yargs": "^5.0.0" | ||
}, | ||
@@ -57,0 +57,0 @@ "repository": { |
@@ -132,3 +132,3 @@ # cheerio-httpcli - Node.js用WEBスクレイピングモジュール | ||
`fetch()`の第3引数である`callback`関数を省略すると、戻り値としてPromiseオブジェクトが返ります。先ほどのサンプルをプロミス形式で呼び出すと以下のようになります。 | ||
`fetch()`の第4引数である`callback`関数を省略すると、戻り値としてPromiseオブジェクトが返ります。先ほどのサンプルをプロミス形式で呼び出すと以下のようになります。 | ||
@@ -219,3 +219,3 @@ ```js | ||
> `fetch()`の第3引数の`callback`関数を指定した場合はPromiseオブジェクトは返しません。したがってコールバック形式で呼び出しつつPromiseオブジェクトで何かをするということはできません。 | ||
> `fetch()`の第4引数の`callback`関数を指定した場合はPromiseオブジェクトは返しません。したがってコールバック形式で呼び出しつつPromiseオブジェクトで何かをするということはできません。 | ||
@@ -490,3 +490,3 @@ ### fetchSync(url[, get-param, encode]) | ||
// フォームのあるページに同期リクエスト | ||
var result1 = client.fetch('http://foo.bar.baz/'); | ||
var result1 = client.fetchSync('http://foo.bar.baz/'); | ||
var form = result1.$('form[name=login]'); | ||
@@ -794,3 +794,3 @@ | ||
このようなHTMLで、`src`の`blank.gif`ではなく`data-original-src`の`http://this.is/real-image.png`をダウンロードしたい場合は以下のように指定します。 | ||
このようなHTMLで、`src`の`blank.gif`ではなく`data-original-src`の`http://this.is/real-image.png`を取得したい場合は以下のように指定します。 | ||
@@ -802,5 +802,5 @@ ```js | ||
`data-original-src`がその要素に存在しない場合は`src`属性のURLをダウンロードします。 | ||
`data-original-src`がその要素に存在しない場合は`src`属性のURLを取得します。 | ||
なお、デフォルトでは`data-original`>`data-lazy-src`>`data-src`>`src`の優先順になっています。デフォルトの優先順位を破棄して`src`属性の画像を最優先でダウンロードしたい場合は、 | ||
なお、デフォルトでは`data-original`>`data-lazy-src`>`data-src`>`src`の優先順になっています。デフォルトの優先順位を破棄して`src`属性の画像を最優先で取得したい場合は、 | ||
@@ -1030,3 +1030,3 @@ ```js | ||
. | ||
// 不要になったら消去 | ||
// 不要になったら消去(これを忘れるとその後別のページにアクセスするときにも認証情報を送信してしまう) | ||
delete(client.headers['Authorization']); | ||
@@ -1048,2 +1048,21 @@ }); | ||
### プロキシサーバー経由でアクセス | ||
環境変数`HTTP_PROXY`に`http://プロキシサーバーのアドレス:ポート/`をセットするとプロキシサーバー経由でWEBページを取得します。 | ||
```js | ||
process.env.HTTP_PROXY = 'http://proxy.hoge.com:18080/'; // プロキシサーバーを指定 | ||
var client = require('cheerio-httpcli'); | ||
client.fetch('http://foo.bar.baz/', ... | ||
``` | ||
### Electronに組み込む | ||
いろいろと工夫するとwebpackで固められますが、それでも`Sync`系メソッドは正常に動作しません(利用不可)。また、webpackの際に大量のwarningが発生するので、その他の機能に関しても正常に動作するかは分かりません。詳細は[こちら](https://github.com/ktty1220/cheerio-httpcli/issues/14#issuecomment-230733142)をご覧ください。 | ||
ご利用の際は自己責任でお願いします。 | ||
また、Electronという環境に起因する動作不良に関しては、ちょっとした修正で解決するものは対応しますが、現行の仕組みを大きく変える必要がある場合は対応しない事もあります。ご了承ください。 | ||
### 文字コード判別の仕様 | ||
@@ -1050,0 +1069,0 @@ |
@@ -118,2 +118,6 @@ /*eslint max-statements:[1, 100]*/ | ||
var loc = _this.url('manual', 'euc-jp'); | ||
if (/_relative/.test(req.url)) { | ||
// 相対パスバージョン | ||
loc = loc.replace(/^http:\/\/localhost:\d+\//, ''); | ||
} | ||
headers = [ | ||
@@ -120,0 +124,0 @@ [ 'location', loc ] |
/*eslint-env mocha*/ | ||
/*eslint no-invalid-this:0, max-len:[1, 150, 2]*/ | ||
/*eslint no-invalid-this:0, max-len:[1, 150, 2], max-nested-callbacks:[1, 6]*/ | ||
/*jshint -W100*/ | ||
@@ -4,0 +4,0 @@ var assert = require('power-assert'); |
/*eslint-env mocha*/ | ||
/*eslint no-invalid-this:0*/ | ||
/*eslint no-invalid-this:0, max-nested-callbacks:[1, 6]*/ | ||
/*jshint -W100*/ | ||
@@ -262,3 +262,3 @@ var assert = require('power-assert'); | ||
}); | ||
cli.timeout = 500; | ||
cli.timeout = 3000; | ||
assert($('.mega').download() === 1); | ||
@@ -265,0 +265,0 @@ }); |
/*eslint-env mocha*/ | ||
/*eslint no-invalid-this:0, no-undefined:0, max-len:[1, 150, 2]*/ | ||
/*eslint no-invalid-this:0, no-undefined:0, max-len:[1, 150, 2], max-nested-callbacks:[1, 6]*/ | ||
/*jshint -W100*/ | ||
@@ -4,0 +4,0 @@ var assert = require('power-assert'); |
/*eslint-env mocha*/ | ||
/*eslint no-invalid-this:0, no-undefined:0, max-len:[1, 150, 2]*/ | ||
/*eslint no-invalid-this:0, no-undefined:0, max-len:[1, 150, 2], max-nested-callbacks:[1, 6]*/ | ||
/*jscs:disable requireDotNotation*/ | ||
@@ -4,0 +4,0 @@ /*jshint -W100*/ |
/*eslint-env mocha*/ | ||
/*eslint no-invalid-this:0, max-len:[1, 150, 2]*/ | ||
/*eslint no-invalid-this:0, max-len:[1, 150, 2], max-nested-callbacks:[1, 6]*/ | ||
/*jshint -W100*/ | ||
@@ -4,0 +4,0 @@ var assert = require('power-assert'); |
/*eslint-env mocha*/ | ||
/*eslint no-invalid-this:0*/ | ||
/*eslint no-invalid-this:0, max-nested-callbacks:[1, 6]*/ | ||
/*jshint -W100*/ | ||
@@ -20,6 +20,7 @@ var assert = require('power-assert'); | ||
it('POST送信後にクッキーがセットされリダイレクト先に飛ぶ', function (done) { | ||
it('POST送信後にクッキーがセットされリダイレクト先に飛ぶ(絶対パス)', function (done) { | ||
var url = helper.url('manual', 'euc-jp'); | ||
cli.fetch(helper.url('form', 'utf-8') + '?reset_trace_route', function (err, $, res, body) { | ||
$('form[name=login]').submit(function (err, $, res, body) { | ||
$('form[name=login]') | ||
.submit(function (err, $, res, body) { | ||
assert(typeOf(res.cookies) === 'object'); | ||
@@ -37,2 +38,21 @@ assert(res.cookies.user === 'guest'); | ||
}); | ||
it('POST送信後にクッキーがセットされリダイレクト先に飛ぶ(相対パス)', function (done) { | ||
var url = helper.url('manual', 'euc-jp'); | ||
cli.fetch(helper.url('form', 'utf-8') + '?reset_trace_route', function (err, $, res, body) { | ||
$('form[name=login]') | ||
.attr('action', '/~redirect_relative') | ||
.submit(function (err, $, res, body) { | ||
assert(typeOf(res.cookies) === 'object'); | ||
assert(res.cookies.user === 'guest'); | ||
assert($.documentInfo().url === url); | ||
assert.deepEqual(JSON.parse(res.headers['trace-route']), [ | ||
'/form/utf-8.html?reset_trace_route', | ||
'/~redirect_relative', | ||
'/manual/euc-jp.html' | ||
]); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -39,0 +59,0 @@ |
/*eslint-env mocha*/ | ||
/*eslint no-invalid-this:0*/ | ||
/*eslint no-invalid-this:0, max-nested-callbacks:[1, 8]*/ | ||
/*jshint -W100*/ | ||
@@ -4,0 +4,0 @@ var assert = require('power-assert'); |
@@ -307,2 +307,23 @@ /*eslint-env mocha*/ | ||
}); | ||
describe('Electron', function () { | ||
beforeEach(function () { | ||
process.versions.electron = '1.0.0'; | ||
}); | ||
it('同期リクエストは未サポート', function () { | ||
try { | ||
cli.fetchSync(helper.url('form', 'utf-8')); | ||
throw new Error('not thrown'); | ||
} catch (e) { | ||
assert(e.message === 'sync request is not support on Electron'); | ||
} | ||
}); | ||
it('非同期リクエストは可能', function () { | ||
cli.fetch(helper.url('form', 'utf-8'), function (err, $, res, body) { | ||
assert(res.statusCode === 200); | ||
}); | ||
}); | ||
}); | ||
}); |
359132
95
6570
1070
Updatedasync@^2.0.1
Updatedhe@^1.1.0
Updatedobject-assign@^4.1.0
Updatedrequest@^2.74.0
Updatedtough-cookie@^2.3.1