Skip to content

Instantly share code, notes, and snippets.

@Akifcan
Created February 12, 2021 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akifcan/72acad176cd4164cc8c14d186afd600e to your computer and use it in GitHub Desktop.
Save Akifcan/72acad176cd4164cc8c14d186afd600e to your computer and use it in GitHub Desktop.
const cheerio = require('cheerio')
const axios = require('axios')
async function searchSong(id, artistname, song) {
artistname = artistname.replace(/ /g, '+')
song = song.replace(/ /g, '+')
const response = await axios.get(`https://www.lyrics.com/lyric/${id}/${artistname}/${song}`) //sayfa kaynak kodunu alıyoruz
const $ = cheerio.load(response.data) // ve kaynak kodunu cheerioya yüklüyoruz
const lyrcis = $('.lyric-body').text(); //az önce tarayıcı konsolunda cevabını aldığımız .lyric-body sınıfını uygulamamızdan aratıyoruz
const songName = $('#lyric-title-text').text()
const artist = $('.lyric-artist a:not(:last-child)').text()
return {
lyrcis, songName, artist
}
}
searchSong('35855210', 'alan walker', 'darkside')
.then(response => {
console.log(response);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment