Last active
September 22, 2025 12:02
-
-
Save mathigatti/fec92ff0fffefd0a2951ec43f4302f43 to your computer and use it in GitHub Desktop.
letras.com scraper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bs4 import BeautifulSoup | |
| import requests | |
| import os | |
| letras_url = "https://www.letras.com" | |
| def descargar_cancion(path): | |
| url = f"{letras_url}{path}" | |
| page = requests.get(url) | |
| soup = BeautifulSoup(page.content, 'html.parser') | |
| letra = "" | |
| for div in soup.find_all("div", {"class": "cnt-letra p402_premium"}): | |
| for p in div.find_all("p"): | |
| text = str(p) | |
| for space in ["</br>","<br>","<br/>","<p>","</p>"]: | |
| text = text.replace(space,"\n") | |
| letra += text | |
| with open(f"{path[1:-1]}.txt",'w') as f: | |
| f.write(letra) | |
| def letras(artista): | |
| url = f"{letras_url}/{artista}/mais_acessadas.html" | |
| page = requests.get(url) | |
| if not os.path.exists(artista): | |
| os.mkdir(artista) | |
| soup = BeautifulSoup(page.content, 'html.parser') | |
| for a in soup.find_all("a", {"class": "songList-table-songName font --base --size16"}): | |
| descargar_cancion(a["href"]) | |
| import sys | |
| artista = sys.argv[1] | |
| letras(artista) | |
| # Usage example | |
| # python3 scrape_letras.py duki | |
| # It should download all songs of "duki" on the folder ./letras/duki |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment