Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download the top n pages of songs from beatsaver.com. Warning: hacked together in 10 minutes and very janky
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
You can’t perform that action at this time.