index.js
Tue Aug 30 2022 15:57:02 GMT+0000 (Coordinated Universal Time)
Saved by
@Retinal
#javascript
const PORT = 8000
const axios = require('axios')
const cheerio = require('cheerio')
const express = require('express')
const app = express()
const url = 'https://www.theguardian.com/us'
axios(url)
.then(response => {
const html = response.data
const $ = cheerio.load(html)
const articles = [
]
$('.fc-item__title', html).each(function() {
const title = $(this).text()
const url = $(this).find('a').attr('href')
articles.push({
title,
url
})
})
console.log(articles)
}).catch(err => console.log(err) )
app.listen(PORT, () => console.log('server running on PORT 8000'))
content_copyCOPY
Comments