Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- urllib
- python
- swift
- node.js
- 날짜
- PyQt
- pandas
- 다이어트
- javascript
- flutter
- MySQL
- 리눅스
- mssql
- MS-SQL
- Unity
- Linux
- ASP
- PyQt5
- 라즈베리파이
- PER
- GIT
- ubuntu
- 함수
- IOS
- Excel
- port
- sqlite
- 맛집
- 유니티
- tensorflow
Archives
아미(아름다운미소)
python file download(urllib, urllib2, tqdm) 본문
파이썬에서 파일을 다운로드하는 방법
- Python 2에서 파일을 다운로드하는 방법import urllib
urllib.urlretrieve ("http://www.example.com/songs/mp3.mp3", "mp3.mp3")
(Python 3+에서는 'import urllib.request'와 urllib.request.urlretrieve를 사용하십시오) - 파이썬에서 파일을로드하는 방법(진행 표시 줄)
import urllib2
url = "http://download.thinkbroadband.com/10MB.zip"
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, 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()
- 파이썬에서 파일을로드하는 방법(진행 표시 줄)
- https://pypi.python.org/pypi/tqdm
from tqdm import tqdm
import requests
url = "http://download.thinkbroadband.com/10MB.zip"
response = requests.get(url, stream=True)
with open("10MB", "wb") as handle:
for data in tqdm(response.iter_content()):
handle.write(data)
'랭귀지 > python' 카테고리의 다른 글
| Python을 사용하여 XML 파싱하기 (0) | 2018.03.04 |
|---|---|
| Python JSON 데이타 (0) | 2018.02.05 |
| 유튜브 (YouTube) 동영상 다운로드하기 (youtube-dl package를 이용) (0) | 2018.01.24 |
| 파이썬(python) 스크린 캡쳐(pyscreenshot) (0) | 2018.01.23 |
| pandas_datareader 를 이용해서 구글 Finance 에서 코스피 가져오기 (0) | 2018.01.21 |
Comments