Skip to content

Instantly share code, notes, and snippets.

@jsuo
Last active January 3, 2017 07:31
Show Gist options
  • Save jsuo/41cec8fb3c8a68a53019d262ce628b22 to your computer and use it in GitHub Desktop.
Save jsuo/41cec8fb3c8a68a53019d262ce628b22 to your computer and use it in GitHub Desktop.
request-promise 使い方
'use strict';
/* library */
const rp = require('request-promise');
const cheerio = require('cheerio');
/* GET option */
let options = {
method: 'GET',
uri: 'http://gizilogger.ghsystems.biz/',
transform: (body) => {
// チェリオで解析して返す。下の($)に渡される。
return cheerio.load(body)
},
};
/* class="span4"を取得 */
rp(options)
.then(($) => {
console.log(`Success:\n${ $('.span4').text().trim() }`);
})
.catch((err) => {
console.log(`${ err.statusCode }:\n${ err }` );
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment