728x90
URL link 파일 다운로드 하는 방법 2가지 입니다.
인터넷에 찾아보면 여려 방법이 나오는데, 축약하면 아래 2가지 입니다.
import urllib.request
# 1 방법
def get_downloadFile(url):
with urllib.request.urlopen(url) as r:
return r.read()
def download_urlFile(url, file=None):
if not file:
file = url.split('/')[-1]
with open(file, 'wb') as f:
f.write(get_downloadFile(url))
# 2 방법
def download_urlFile_2(url,file=None):
if not file:
file = url.split('/')[-1]
#file_name, headers = urllib.request.urlretrieve(url)
#print(file_name, headers)
urllib.request.urlretrieve(url, file)
참조하세요.
728x90
'언어 > Python' 카테고리의 다른 글
Python email 보내기 ( google smtp server 사용) (0) | 2018.06.14 |
---|---|
QT5 push button color checkbox color combobox color (0) | 2018.03.07 |
리눅스 우분투 자바 인스톨 (0) | 2017.12.07 |
Python qt label link picture 라벨 링크 이미지 사진 (0) | 2017.10.24 |
python web text 가져오기 (3) | 2017.09.21 |