identification mostly working
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
const got = require('got')
|
||||
const cheerio = require('cheerio')
|
||||
const fs = require('fs')
|
||||
const PLAYLIST_URL = 'https://nintendoradioplaylist2.000webhostapp.com/Livestream%20Playlist.html'
|
||||
|
||||
got('https://nintendoradioplaylist2.000webhostapp.com/Livestream%20Playlist.html').then(res => {
|
||||
const $ = cheerio.load(res.body)
|
||||
const playlist = []
|
||||
$('#playlistTableBody tr').each((i, row) => {
|
||||
cells = $(row).find('td')
|
||||
album = $(cells[1]).text()
|
||||
track = $(cells[2]).text()
|
||||
duration = $(cells[3]).text()
|
||||
playlist.push({album, track, duration})
|
||||
})
|
||||
fs.writeFileSync('playlist.json', JSON.stringify(playlist))
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
function scrapePlaylist(url) {
|
||||
got(url).then(res => {
|
||||
const $ = cheerio.load(res.body)
|
||||
const playlist = []
|
||||
$('#playlistTableBody tr').each((i, row) => {
|
||||
const cells = $(row).find('td')
|
||||
const album = $(cells[1]).text()
|
||||
const track = $(cells[2]).text()
|
||||
const duration = $(cells[3]).text()
|
||||
playlist.push({album, track, duration})
|
||||
})
|
||||
fs.writeFileSync('playlist.json', JSON.stringify(playlist))
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
scrapePlaylist
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
scrapePlaylist(PLAYLIST_URL)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user