Skip to content

Commit abfa329

Browse files
authored
Merge pull request metafy-social#428 from nabroleonx/master
Add lyrics scraper script
2 parents 2d95dcb + 6ad5467 commit abfa329

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
4+
5+
def get_lyrics(artist, song):
6+
song_url = 'http://www.azlyrics.com/lyrics/' + artist + '/' + song + '.html'
7+
8+
response = requests.get(song_url)
9+
10+
soup = BeautifulSoup(response.content, 'html.parser')
11+
try:
12+
lyrics = soup.find(
13+
'div', class_='col-xs-12 col-lg-8 text-center').find_all('div')[5].text
14+
print(lyrics)
15+
except AttributeError:
16+
print("Please make sure you have entered the correct name(i.e. Don't add spaces between words)!")
17+
18+
19+
artist = input(
20+
"Enter the name of the artist/band: ").strip().lower().replace(' ', '')
21+
song = input("Enter the name of the song: ").strip().lower().replace(' ', '')
22+
get_lyrics(artist, song)

scripts/Lyrics Scraper/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Lyrics scraper
2+
3+
This simple script scrapes [Azlyrics](http://www.azlyrics.com) given the artist and the song name.
4+
5+
## Usage
6+
7+
It's pretty straight-forward, just install the requiremnts and run it.
8+
9+
`pip install -r requirements.txt`
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bs4
2+
requests

0 commit comments

Comments
 (0)