-
Notifications
You must be signed in to change notification settings - Fork 0
/
lyrics.py
44 lines (31 loc) · 1.17 KB
/
lyrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from bs4 import BeautifulSoup
import urllib.request
import urllib.error
import urllib.parse
class Scraper():
def __init__(self, song, singer):
song = song.lower()
self.song = "".join(song.split())
singer = singer.lower()
self.singer = "".join(singer.split())
def get_lyrics(self):
print("\n[*] Scraping off lyrics...")
url = 'https://www.azlyrics.com/lyrics/' + self.singer+'/' + self.song+'.html'
raw = urllib.request.urlopen(url)
data = raw.read()
soup = BeautifulSoup(data, 'html.parser')
l = soup.find_all("div", attrs={"class": None, "id": None})
lyrics = [i.getText() for i in l]
return lyrics
def write_infile(self, lyrics):
file = open(self.song + ".txt", 'w')
file.write(lyrics[0])
file.close()
if __name__ == "__main__":
song = input("[?] Enter song: ")
singer = input("[?] Enter singer: ")
s = Scraper(song, singer)
lyrics = s.get_lyrics()
s.write_infile(lyrics)
print("\n[*] Lyrics is stored in file with name " + s.song + ".txt")
#This code is contributed by techcentaur