From 8014bc1d368a0eb7cb6b01ca02cdbeee283637d2 Mon Sep 17 00:00:00 2001 From: nabroleonx Date: Fri, 14 Oct 2022 23:43:07 +0300 Subject: [PATCH] Add lyrics scraper script --- scripts/Lyrics Scraper/LyricsScraper.py | 21 +++++++++++++++++++++ scripts/Lyrics Scraper/README.md | 9 +++++++++ scripts/Lyrics Scraper/requirements.txt | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 scripts/Lyrics Scraper/LyricsScraper.py create mode 100644 scripts/Lyrics Scraper/README.md create mode 100644 scripts/Lyrics Scraper/requirements.txt diff --git a/scripts/Lyrics Scraper/LyricsScraper.py b/scripts/Lyrics Scraper/LyricsScraper.py new file mode 100644 index 0000000..d32dfba --- /dev/null +++ b/scripts/Lyrics Scraper/LyricsScraper.py @@ -0,0 +1,21 @@ +import requests +from bs4 import BeautifulSoup + + +def get_lyrics(artist, song): + song_url = 'http://www.azlyrics.com/lyrics/' + artist + '/' + song + '.html' + + response = requests.get(song_url) + + soup = BeautifulSoup(response.content, 'html.parser') + try: + lyrics = soup.find( + 'div', class_='col-xs-12 col-lg-8 text-center').find_all('div')[5].text + print(lyrics) + except AttributeError: + print("Please make sure you have entered the correct name!") + + +artist = input("Enter the name of the artist/band: ").strip().lower() +song = input("Enter the name of the song: ").strip().lower() +get_lyrics(artist, song) diff --git a/scripts/Lyrics Scraper/README.md b/scripts/Lyrics Scraper/README.md new file mode 100644 index 0000000..95cf968 --- /dev/null +++ b/scripts/Lyrics Scraper/README.md @@ -0,0 +1,9 @@ +# Lyrics scraper + +This simple script scrapes [Azlyrics](http://www.azlyrics.com) given the artist and the song name. + +## Usage + +It's pretty straight-forward, just install the requiremnts and run it. + +`pip install -r requirements.txt` diff --git a/scripts/Lyrics Scraper/requirements.txt b/scripts/Lyrics Scraper/requirements.txt new file mode 100644 index 0000000..d779dbe --- /dev/null +++ b/scripts/Lyrics Scraper/requirements.txt @@ -0,0 +1,2 @@ +bs4 +requests \ No newline at end of file