Last active
May 7, 2018 15:44
-
-
Save daejinseok/028d70ec65d366f284de7275627dc5fd to your computer and use it in GitHub Desktop.
python3 http://ropas.snu.ac.kr/~kwang/4190.310/mooc/ downloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/serithemage/python_exercise/blob/master/downloader/downloader.py | |
# 이 python2으로 작성되어 있어, 참조하여 python3으로 재작성하였습니다. | |
# beautifulsoup4가 없는 분들은 아래처럼 pip로 통해 설치하세요. | |
# pip install beautifulsoup4 | |
import urllib | |
import threading | |
import urllib.request | |
import time | |
from bs4 import BeautifulSoup | |
url = "http://ropas.snu.ac.kr/~kwang/4190.310/mooc/" | |
html_doc = urllib.request.urlopen(url).read() | |
soup = BeautifulSoup(html_doc, 'html.parser') | |
mp4list = [] | |
for link in soup.find_all('a'): | |
href = link.get('href') | |
if href != None and href.endswith('.mp4'): | |
mp4list.append(href) | |
def download(url, fileName): | |
urllib.request.urlretrieve(url+fileName, fileName) | |
print(fileName + " download end") | |
for mp4 in mp4list: | |
while 10 < threading.activeCount(): | |
time.sleep(3) | |
t = threading.Thread(target=download, args=(url, mp4)) | |
t.daemon = True | |
t.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment