I found a dataset of lyrics from here. But this dataset has only bag of words where the ordering of the words in the songs is lost. Is there any way to get a dataset of entire lyrics as such?
Song lyrics are going to be mostly copyrighted, so distributing them as a dataset would probably not be legally possible.
To collect lyrics you can scrape one of the many lyrics websites. Here are some steps for how to do so with azlyrics.com
Find a page that lists all artists:
Find URL to one artist:
Find URL to one song:
Of course, you can't do this manually. But with some simple code, it's not hard to find URLs on a page, then go to those pages and find new URLs. Because you know the structure of the website, specifically where lists of artists are stored in a page called a.html, it's straightforward.
Here's a more technical description. Each artist page has a section of HTML like this:
<div class="artists fr"> <a href="a/anathema.html">ANATHEMA</a><br /> <a href="a/anberlin.html">ANBERLIN</a><br /> <a href="b/bonnieanderson.html">ANDERSON, BONNIE</a><br /> <a href="a/andersoneast.html">ANDERSON EAST</a><br /> <a href="j/johnanderson.html">ANDERSON, JOHN</a><br /> <a href="k/keithanderson.html">ANDERSON, KEITH</a><br /> <a href="a/andreabocelli.html">ANDREA BOCELLI</a><br /> <a href="a/andreacorr.html">ANDREA CORR</a><br /> <a href="a/andreasbourani.html">ANDREAS BOURANI</a><br /> ... </div>
Each song has HTML structure like this:
<b>"Fuck Me Pumps"</b><br /> <div style="margin-left:10px;margin-right:10px;"> <!-- start of lyrics --> When you walk in the bar,<br /> And you dressed like a star,<br /> Rockin' your F me pumps.<br />
<!-- start of lyrics --> will be a great help to scraping!
Here is an outline of a python code to get your started:
import requests # step 1 - get artist pages for page in ['abcdefghijklmnopqrstuvwxyz']: # also add '19' url = 'http://www.azlyrics.com/' + page + '.html' # construct url of artists page html = requests.get(url) # download a.html # parse HTML for list of URLs to artists # step 2 - make unique list of URLs to artists # step 3 - loop over artist URLs to get list of URLs to songs # go to song HTML page and parse into text.
If you want to license lyrics, you either have to contract with individual owners, or with a clearinghouse like lyricsfind.com (who have agreements with many individual owners). I have spoken to Roy Hennig at lyricsfind.com and they have many ways to license them (full view lyrics on web, partial, etc). They might be open to licensing lyrics for analytics needs, I don't know. I don't like to endorse any companies, but when I called around last year, they were the only ones still licensing. I also tried gracenote (Shannon in sales), but they were no longer providing the service.
That's the legal way to do it anyway. I do not know of an open way to access lyrics for research or "fun" data analysis, but I would like to know.