movii
6/28/2017 - 4:55 AM

笔记:「饭否精选·日历」微信小程序制作记录-爬虫部分:3. 筛选、保存索引

笔记:「饭否精选·日历」微信小程序制作记录-爬虫部分:3. 筛选、保存索引

const ENTRIES_URL = 'http://blog.fanfou.com/digest/json/index.json'

function loadAllURls() {
  //  load all url from 'http://blog.fanfou.com/digest/json/index.json'
  return request(ENTRIES_URL)
    // JSON.parse(string) => json
    .then(data => JSON.parse(data))
    // format [..., './json/2017-05-15.weekly.json', ...]
    // to [..., '2017-05-15.weekly', ...]
    .then(entries => entries.map(entry => entry.replace(/^\.\/json\/|\.json$/ig, '')))
    // only need '*.daily'
    .then(entries => entries.filter(e => e.includes('daily')))
}

loadAllURls().then(data => console.log(data));