1

So I have to do a project for school, I need to create a simple website who uses an API. I want to use the genius API to collect the lyrics but you can't because of copyright. I can only use the API to find certain information about a song like creator, url of the cover{image}, or song link (genius). So if I want to get the lyrics I need to scrape the link of the song. I have some problems with scraping because it's usually accomplished with node.js and I can't use node.js because it's not allowed in the project.

Do anybody have an idea how to scrape this link to find the lyrics only with pure javascript (i can also use jQuery): https://genius.com/Lil-peep-white-tee-lyrics

I know that the html page contain a tag and all the lyrics are here.

Example :

<div class="lyrics">
   <p> This is the lyrics</p>
</div>

If anybody has an idea it would be very helpful. Thanks

AnonymZ
  • 78
  • 1
  • 11
  • Does this answer your question? [Selecting

    within a div using jQuery](https://stackoverflow.com/questions/11077977/selecting-p-within-a-div-using-jquery)

    – Rafik Farhad May 28 '20 at 17:57

2 Answers2

2

The problem you are running into is actually a fairly common issue in programming. It's easy to underestimate the complexity of a system before getting down to implementing it, or to find that a platform is not capable of handling the task you need it to. In these cases, you need to be able to do one of two things, either redefine the system you're building, or expand the framework you're building it on.

You said this is for a school assignment where the objective is to consume an api. My first step would be to talk to your instructor to see if the project's goals can be redefined to only include the information provided through the api. If getting the lyrics is required, the next attempt should be to find an api that can provide them like this one. https://developer.musixmatch.com/plans.

Scraping webpages should be the last resort.

Charlie Bamford
  • 1,268
  • 5
  • 18
1

By using jQuery try to learn how to select specific html section by tag, class or id.

var myLyrics = $('.lyrics')​.find('div:first')​.find(​'p:first')​​​.html();
alert(myLyrics);
Rafik Farhad
  • 1,182
  • 2
  • 12
  • 21
  • I know how to use jQuery, but my problem is that i need to do this on an other page (www.genius.com), how can i use jQuery selector on a remote page, do i need to dowload the page and then select in it or can i do it by another way ? – AnonymZ May 28 '20 at 18:04
  • Yes. You have to load the html of webpage you want to scrap. – Rafik Farhad May 28 '20 at 18:18
  • Thanks mate, but how to simply load a distant page and use jQuerry selector on it ? – AnonymZ May 28 '20 at 18:21
  • It's kinda tricky at some point. I can refer you https://forum.jquery.com/topic/parse-html-from-url-using-jquery. But it has some complexity. If the remote server does not allow CORS then you can not parse the web page from the browser. You can try. – Rafik Farhad May 28 '20 at 18:34