@Kognise/

MediumRecommended

Nodejs

No description

fork
loading
Files
  • index.js
  • package-lock.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const fetch = require('node-fetch')
const cheerio = require('cheerio')

fetch('https://medium.com/').then((res) => {
  return res.text()
}).then((markup) => {
  const $ = cheerio.load(markup)

  $('.extremeHero-postContent').each((_, dom) => {
    const element = $(dom)

    const title = element.find('.extremeHero-titleClamp h1, .extremeHero-titleClamp h2').text()
    const href = element.find('a').attr('href').replace(/\?.+$/, '')
    const summary = element.find('.ui-summary').text()

    console.log(`${title}\n(${href})\n${summary}\n\n`)
  })
})
node v10.16.0