Skip to content

Instantly share code, notes, and snippets.

@Ozymandias42
Last active July 11, 2020 15:00
Show Gist options
  • Save Ozymandias42/fac8cd3d74301a3df50d94709ff325d4 to your computer and use it in GitHub Desktop.
Save Ozymandias42/fac8cd3d74301a3df50d94709ff325d4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from bs4 import BeautifulSoup
import requests
import re
import sys
if len(sys.argv) == 3:
URL=str(sys.argv[1])
cookie=dict(MoodleSession=str(sys.argv[2]))
else:
print("Run with downloader url session_cookie_fingerprint")
quit()
rawhtml=requests.get(URL,cookies=cookie, allow_redirects=True).text
soup=BeautifulSoup(rawhtml,'lxml')
def has_file_or_dir(href):
return href and re.compile("https.+resource.+[0-9]{6}$").search(href)
links = soup.find_all(href=has_file_or_dir)
for link in links:
filename=str(link.contents[1].contents[0])
with open(filename,'wb') as f:
for chunk in requests.get(link['href'],cookies=cookie,allow_redirects=True, stream=True).iter_content(chunk_size=1024):
if chunk: f.write(chunk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment