-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractor_Python3.py
32 lines (25 loc) · 1.04 KB
/
extractor_Python3.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
from bs4 import BeautifulSoup
import urllib.request, urllib.error, urllib.parse
def generating(artist, title, save):
artist = artist.lower().replace(" ", "%20")
title = title.lower().replace(" ", "%20")
generate_url = 'http://azlyrics.com/lyrics/'+artist+'/'+title +'.html'
processing(generate_url, artist, title, save)
def processing(generate_url, artist, title, save):
response = urllib.request.urlopen(generate_url)
read_lyrics = response.read()
soup = BeautifulSoup(read_lyrics)
lyrics = soup.find_all("div", attrs={"class": None, "id": None})
lyrics = [x.getText() for x in lyrics]
printing(artist, title, save, lyrics)
def printing(artist, title, save, lyrics):
for x in lyrics:
print(x, end="\n\n")
if save == True:
saving(artist, title, lyrics)
elif save == False:
pass
def saving(artist, title, lyrics):
f = open(artist + '_' + title + '.txt', 'w')
f.write("\n".join(lyrics).strip())
f.close()