Skip to content

Commit 8014bc1

Browse files
committed
Add lyrics scraper script
1 parent 2d95dcb commit 8014bc1

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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!")
17+
18+
19+
artist = input("Enter the name of the artist/band: ").strip().lower()
20+
song = input("Enter the name of the song: ").strip().lower()
21+
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)