Created
June 1, 2019 01:53
-
-
Save nacgarg/ad1043f62c1a061987ff52f59badb9e7 to your computer and use it in GitHub Desktop.
Download the top n pages of songs from beatsaver.com. Warning: hacked together in 10 minutes and very janky
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 lxml import html | |
import wget | |
import zipfile | |
import os | |
asd = 0 | |
def download_page(page_num): | |
global asd | |
r = requests.get('https://beatsaver.com/browse/downloads/'+str(page_num)+'0') | |
tree = html.fromstring(r.content) | |
links = tree.xpath('//a[@class="button"]') | |
for l in links: | |
if l.text == "Download Zip": | |
print (l.get('href')) | |
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} | |
res = requests.get(l.get('href'), headers=headers) | |
with open(str(asd) + '.zip', 'wb') as f: | |
f.write(res.content) | |
zip_ref = zipfile.ZipFile(str(asd) + '.zip', 'r') | |
zip_ref.extractall(".") | |
zip_ref.close() | |
os.remove(str(asd) + '.zip') | |
asd+=1 | |
for i in range(1, input("How many pages to download? ")+1): | |
download_page(i) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment