1.這是程式
依賴request函式庫
node v6.9.5
npm v4.5.0
var request = require('request')
var fs = require('fs')
var url = 'http://rest.wufazhuce.com/OneForWeb/one/getHpinfo?strDate='
var d = new Date()
var downUrl = url + d.toLocaleDateString()
request(downUrl, ((error, res, body) => {
var content = JSON.parse(body)
// console.log(body)
console.log(content.hpEntity.strThumbnailUrl)
request(content.hpEntity.strThumbnailUrl).pipe(fs.createWriteStream(content.hpEntity.strHpTitle + '.jpg'))
}))
#2.這是請求的json資料
{
"result": "SUCCESS",
"hpEntity": {
"strLastUpdateDate": "2017-05-09 11:42:51",
"strDayDiffer": "0",
"strHpId": "1702",
"strHpTitle": "VOL.1675",
"strThumbnailUrl": "http:\/\/image.wufazhuce.com\/FunJK0ZcKgrsYo92v1fK7-v5-ZEN",
"strOriginalImgUrl": "http:\/\/image.wufazhuce.com\/FunJK0ZcKgrsYo92v1fK7-v5-ZEN",
"strAuthor": "绘画",
"strContent": "我希望心里的夏季和身外的夏季一样完美,让我忘记终年终日的等待。可是心灵没有夏季。我望着夏季走过,自己却留在了冬季。",
"strMarketTime": "2017-05-09",
"sWebLk": "http:\/\/m.wufazhuce.com\/one\/1702",
"strPn": "",
"wImgUrl": ""
}
}
當然是非法的了
可以了
還是要引用一個日期格式化的小短庫,就用dateformat吧源碼200多行
使用dateFormat(new Date(), "yyyy-mm-dd")即可取得2017-05-10格式日期