Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Download the top n pages of songs from 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(''+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:
zip_ref = zipfile.ZipFile(str(asd) + '.zip', 'r')
os.remove(str(asd) + '.zip')
for i in range(1, input("How many pages to download? ")+1):
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.