Last active
August 31, 2018 17:34
-
-
Save sergiolucero/9d7080ec49f0477954201e9d65291467 to your computer and use it in GitHub Desktop.
canciones de un artista en LaCuerda.net
This file contains 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
import requests | |
from bs4 import BeautifulSoup | |
from operator import methodcaller | |
url_bs = lambda url: BeautifulSoup(requests.get(url).text,'html5lib') # magic! | |
def recopila_acordes(artista = 'Manu Chao'): # "Manu Chao" -> manu_chao | |
fartist = '_'.join(map(methodcaller("lower"),artista.split())) | |
url = f'https://acordes.lacuerda.net/{fartist}/' | |
songs = url_bs(url).find_all('ul',attrs={'class':'b_main'})[0].find_all('a') | |
songs = [(s.text, url+s['href']+'.shtml') for s in songs] | |
fetch = {' '.join(s[0].split()[:-1]): url_bs(s[1]) for s in songs} | |
fetched = {} | |
for song_name, song_page in fetch.items(): | |
fv = song_page.find_all('div',attrs={'id':'t_body'}) | |
try: | |
fetched[song_name] = fv[0].text | |
except: | |
print("Unexpected error:", sys.exc_info()[0]) | |
print('Encontré %d canciones para %s' %(len(fetched), artista)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment