Skip to content

Instantly share code, notes, and snippets.

@lowweihong
Last active August 31, 2019 09:04
Show Gist options
  • Save lowweihong/6b65e8f3abfbc22f88bde395978cd3a3 to your computer and use it in GitHub Desktop.
Save lowweihong/6b65e8f3abfbc22f88bde395978cd3a3 to your computer and use it in GitHub Desktop.
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
links = []
def handle_starttag(self, tag, attrs):
if tag != 'a':
return
for attr in attrs:
if 'href' in attr[0]:
if attr[1].endswith('format=midi'):
self.links.append(attr[1])
break
parser = MyHTMLParser()
parser.feed(r.text)
for url in parser.links:
if is_downloadable(url):
wget.download(url, './data/' + url.split('&file=')[-1].split('&format')[0] + '.mid')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment