initial
This commit is contained in:
commit
74ae93a96e
1 changed files with 94691 additions and 0 deletions
61
joplin notion extension/Web Development/API/genius.md
Normal file
61
joplin notion extension/Web Development/API/genius.md
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
genius
|
||||
|
||||
|
||||
```js
|
||||
|
||||
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)
|
||||
|
||||
```
|
||||
Loading…
Reference in a new issue