mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
Merge pull request #428 from nabroleonx/master
Add lyrics scraper script
This commit is contained in:
commit
abfa3294e6
22
scripts/Lyrics Scraper/LyricsScraper.py
Normal file
22
scripts/Lyrics Scraper/LyricsScraper.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
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(i.e. Don't add spaces between words)!")
|
||||
|
||||
|
||||
artist = input(
|
||||
"Enter the name of the artist/band: ").strip().lower().replace(' ', '')
|
||||
song = input("Enter the name of the song: ").strip().lower().replace(' ', '')
|
||||
get_lyrics(artist, song)
|
9
scripts/Lyrics Scraper/README.md
Normal file
9
scripts/Lyrics Scraper/README.md
Normal file
|
@ -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`
|
2
scripts/Lyrics Scraper/requirements.txt
Normal file
2
scripts/Lyrics Scraper/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
bs4
|
||||
requests
|
Loading…
Reference in New Issue
Block a user