Skip to content

Instantly share code, notes, and snippets.

@johwanghee
Created June 19, 2018 00:47
Show Gist options
  • Save johwanghee/e282a1fe3ee8e89c1156b91233d18728 to your computer and use it in GitHub Desktop.
Save johwanghee/e282a1fe3ee8e89c1156b91233d18728 to your computer and use it in GitHub Desktop.
python requests file download
import requests
import re
import time
url_base = 'http://xxx.site/{}.mp3'
def download(name):
url = url_base.format(name)
print(url)
r = requests.get(url, allow_redirects=True)
filename = '{}.mp3'.format(name)
open(filename, 'wb').write(r.content)
for i in range(1, 31):
index = '{:02}'.format(i)
url = url_base.format(index)
name = index
download(name)
name = '0{}_1'.format(index)
download(name)
name = '0{}_2'.format(index)
download(name)
name = '0{}_3'.format(index)
download(name)
name = '0{}_4_1'.format(index)
download(name)
name = '0{}_4_2'.format(index)
download(name)
name = '0{}_5'.format(index)
download(name)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment