joplin-notes/joplin notion extension/Web Development/API/genius.md
2026-11-04 00:33:23 +05:30

1.2 KiB

genius


const {parse}=require('node-html-parser')
const fetch= require('node-fetch')

async function fetchLyricsFromLink(lyricUrl){
	const lyricContainerSelector= 'div[data-lyrics-container="true"]' 

	// const htmlString= fs.readFileSync('lyrics.html')


	const res= await fetch('https://genius.com/Green-day-the-american-dream-is-killing-me-lyrics')
	const htmlString= await res.text();

	// const htmlString= `<div>
	// 	<div id="lis">
	// 		<ul>
	// 			<li>first</li>
	// 			<li>second</li>
	// 		</ul>
	// 	</div>
	// </div>`

	const root = parse(htmlString)

	// const obj=root.querySelector(lyricContainerSelector)
	const arr=root.querySelectorAll(lyricContainerSelector)


	// console.log(obj.outerHTML)

	let str=""

	for(let element of arr){
		// statements
		str+=element.textContent
		str+='\n'

	}

	return str;

// fs.writeFileSync('parsed_lyrics.html',str)


}

fetch('https://genius.com/api/search/multi?per_page=5&q=Faith --Weeknd')
.then(res=>res.json())
.then(async(data)=>{
	const url= data.response.sections[0].hits[0].result.url
	console.log('url: ',url)
	const lyrics= await fetchLyricsFromLink(url)
	console.log('lyrics: ',lyrics)
})
.catch(console.log)