-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet_Song_Lyrics_From_Viasonat_Cat_Web_Scraping.py
76 lines (56 loc) · 2.67 KB
/
Get_Song_Lyrics_From_Viasonat_Cat_Web_Scraping.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import time
from bs4 import BeautifulSoup
import requests
# TODO -> create a GUI to run this program
# TODO -> use TYPER for CLI implementation
def get_lyric_save_on_txt_file(link=None):
# The User Inserts here a valid viasona.cat link of a song lyric
if link is None:
print("Insert Web Link from Viasona.Cat:\n")
WEB = input()
else:
WEB = link
response = requests.get(WEB)
web_page = response.text
soup = BeautifulSoup(web_page, "html.parser")
# We get hold of the title here
song_title = soup.find(name="h1", attrs={"class": "titol-pagina"})
# We get hold of the group name or singer here
group_or_singer = soup.find(name="h2", attrs={"class": "subtitol-pagina"})
# We get hold of the lyrics here
lyrics = soup.find_all(
name="div", attrs={"class": "enc-lletra__lletra user-text seleccionable"}
)
# Declare a new list and append name of song and group
song_lyrics = []
song_lyrics.append("Title: " + song_title.text + "\n\n")
song_lyrics.append("Group / Singer: " + group_or_singer.text + "\n\n")
# print(song_lyrics)
# We now append all the lyrics, line by line
for lyric in lyrics:
song_lyrics.append(lyric.text)
# We create a new .txt file and add the lyrics to it
with open(
f"Lyrics_from_viasona/{song_title.text} from {group_or_singer.text}.txt", "w"
) as lyrics_file:
for line in song_lyrics:
lyrics_file.write(line)
# ----------------------------------------------------------------
done = """
.----------------. .----------------. .-----------------. .----------------.
| .--------------. || .--------------. || .--------------. || .--------------. |
| | ________ | || | ____ | || | ____ _____ | || | _________ | |
| | |_ ___ `. | || | .' `. | || ||_ \|_ _| | || | |_ ___ | | |
| | | | `. \ | || | / .--. \ | || | | \ | | | || | | |_ \_| | |
| | | | | | | || | | | | | | || | | |\ \| | | || | | _| _ | |
| | _| |___.' / | || | \ `--' / | || | _| |_\ |_ | || | _| |___/ | | |
| | |________.' | || | `.____.' | || ||_____|\____| | || | |_________| | |
| | | || | | || | | || | | |
| '--------------' || '--------------' || '--------------' || '--------------' |
'----------------' '----------------' '----------------' '----------------'
"""
print(done)
# ----------------------------------------------------------------
if __name__ == "__main__":
get_lyric_save_on_txt_file()
time.sleep(3)