Skip to content

Instantly share code, notes, and snippets.

@sergiolucero
Last active August 31, 2018 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergiolucero/9d7080ec49f0477954201e9d65291467 to your computer and use it in GitHub Desktop.
Save sergiolucero/9d7080ec49f0477954201e9d65291467 to your computer and use it in GitHub Desktop.
canciones de un artista en LaCuerda.net
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