Last active
August 31, 2019 09:04
-
-
Save lowweihong/6b65e8f3abfbc22f88bde395978cd3a3 to your computer and use it in GitHub Desktop.
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 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