import sys
import io

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

import urllib.request

imgUrl = "http://imgnews.naver.net/image/002/2017/03/13/0002026985_001_20170313153101670.jpg"
htmlUrl = "http://google.com"

savePath = "C:/Users/cuzai/Desktop/Web_Crawling/cat.png"
savePath2 = "C:/Users/cuzai/Desktop/Web_Crawling/index.html"

f = urllib.request.urlopen(imgUrl).read() #url의 컨텐츠(사진) 읽어내기
f2 = urllib.request.urlopen(htmlUrl).read()

saveFile1 = open(savePath, 'wb') #w : write, r : read, a : add, b : binary
saveFile1.write(f) # 위치에 사진을 써라

saveFile1.close()

with open(savePath2, 'wb') as saveFile2 :
    saveFile2.write(f2)


print("다운로드 완료")
