Notice
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- python3
- Jupyter notebook
- shakeratos
- YouTube 8M
- Deep Learning
- keras
- python
- raspberry pi
- ppc64le
- colaboratory
- Windows 10
- FIle
- ubuntu
- 딥러닝
- CUDA
- error
- windows
- gpu memory
- colab
- dataset
- TensorFlow
- install
- urllib
- face_recognition
- download
- object detection
- Anaconda
- linux
- dlib
- pyTorch
Archives
- Today
- Total
Shakerato
Python code to download file on the internet using urllib library (python 3) 본문
Research
Python code to download file on the internet using urllib library (python 3)
Shakeratto 2018. 6. 1. 10:50import urllib.request as urllib2
import time
import logging
def fileDownload(url, file_name):
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('[fileDownload]')
num_of_retries = 3
time_interval = 2
for retrycnt in range(num_of_retries):
try:
u = urllib2.urlopen(url)
break
except Exception as e:
logger.error(' Faild to download: ' + str(e) + ', Number of remaining attempts: ' \
+ str(num_of_retries - retrycnt - 1))
time.sleep(time_interval)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(dict(meta.items())['Content-Length'])
print('Downloading: ', file_name, ' Bytes: ', file_size)
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print(status)
f.close()
if __name__ == "__main__":
url = '[file_url_to_download]'
file_name = '[file_name_to_save]'
fileDownload(url, file_name)
my github url:
https://github.com/entymos/crawling/blob/master/python3_file_download
refer to here:
'Research' 카테고리의 다른 글
Comments