Skip to content

Instantly share code, notes, and snippets.

@bl4ckbo7
Created August 13, 2020 22:59
Show Gist options
  • Save bl4ckbo7/26f1866c1a8a2aae12ae1061cec598cd to your computer and use it in GitHub Desktop.
Save bl4ckbo7/26f1866c1a8a2aae12ae1061cec598cd to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
#Title: Scraper 1.0 (Just wanted to share, you might want to use it when downloading various courses from this repository. Enjoy. ;))
#Author: bl4ckbo7
#Date/Time: Aug 13, 2020 | 23:43 HRS
import requests
from bs4 import BeautifulSoup
import re
def parser(url, tag, selector):
try:
r = requests.get(url)
page = r.text
except:
print("Error opening the url")
soup = BeautifulSoup(page, 'html.parser')
output = soup.select(tag, selector)
outputname = []
for i in output:
outputname.append(i.text)
outputname.remove('..')
outputname.sort()
return outputname
def main():
#the url of index repository
url = "https://udemy.pundeermaza.xyz/?/Udemy%20-%20The%20Complete%20Networking%20Fundamentals%20Course/"
"""
List the repository's directories
"""
dirs = []
dirs = parser(url, 'a', {"class":"icon icon-dir"})
for i in dirs:
print(i)
#saving directory names into the file
with open('repos.txt', 'w') as file:
for i in dirs:
file.write(i)
"""
Download a directory's file(s)
"""
savedir = input("\nChoose the name of directory you want to download its files: (Format: XXX. directory name/)")
try:
dirs.index(savedir)
saveurl = url + savedir + "/"
except ValueError:
print("No such directory in the repository!\n")
exit()
files = []
files = parser(saveurl, 'a', {"class":"icon-file"})
for thisfile in files:
print("Downloading \"{0}\" ...".format(thisfile))
r = requests.get(saveurl + thisfile, allow_redirects=True)
open(thisfile, 'wb').write(r.content)
print("Finished downloading \"{0}\". \n\n".format(thisfile))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment