Last active
January 3, 2017 07:31
-
-
Save jsuo/41cec8fb3c8a68a53019d262ce628b22 to your computer and use it in GitHub Desktop.
request-promise 使い方
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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