Created
December 3, 2015 08:08
-
-
Save neoneo40/569476a41b67a1e0962d to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
__author__ = 'pr0ximo' | |
# 필독! | |
# 본 자료는 파이썬 교육을 위해 코드 활용의 목적을 위해서만 제작된 코드이며, 불법적인 용도로 사용될수 없습니다. | |
# 또한 본 코드의 불법적인 사용으로 인한 모든 법적또는 신체적/정신적 책임은 본 코드 제작자가 일절 책임지지 않습니다. | |
# 본자료는 로그인이 필요한 유료/무료 웹툰을 가져올수 없습니다. | |
# 또한 그걸 제공 해서 배포할 생각도 없습니다. ㅎ | |
# 사용가능한 URL | |
# http://www.lezhin.com/comic/gundo/p1 | |
import urllib2, sys, re | |
from Tkinter import * | |
# 전역 변수를 제공 하기 위한 클래스. | |
class ShareObject: | |
txtURL = object() | |
# so := Shared Object. | |
so = ShareObject() | |
# 가져오기 버튼에 대한 콜백 함수. | |
def getURLFromTextField(): | |
strURL = so.txtURL.get("1.0", END) | |
# 문자열의 마지막 문자가 개행문자일경우 개행문자 제거. | |
if strURL[-1] == '\n': | |
strURL = strURL[0:-1] | |
regularURL = 'http://cdn.lezhin.com/episodes' + stringProcessor(strURL) + '/contents/%d' | |
saveAll(regularURL) | |
return | |
# 웹 서버로부터 응답을 받아오는 함수. | |
def getResponseFromHTTP(url): | |
# http를 넣어야 하는듯..? | |
if not ("http://" in url): | |
url = "http://" + url | |
bo = urllib2.build_opener() | |
response = bo.open(url) | |
return response.read() | |
# 레진 코믹스의 이미지 URL주소를 가져오기 위해. | |
# URL패턴은 고정URL + 웹툰_고유주소 + 고정URL. | |
def stringProcessor(url): | |
# 'http://' 접두어를 자른다. | |
urlStart = 0 | |
i = 0 | |
while True: | |
if url[i] == 'w' or url[i] == '.': # 'w'나 '.'이 나타났다. | |
break | |
i = i + 1 | |
withOutHTTPPrefix = url[i:] | |
# '/'을 기준으로 URL을 자른다. | |
splited = withOutHTTPPrefix.split('/') | |
# 웹툰의 고유 주소만 합친다. | |
ret = '' | |
for s in splited[2:]: | |
ret += ('/' + s) | |
return ret | |
def saveAll(regUrl): | |
i = 1 | |
while True: | |
# %d 부분을 숫자로 교체. | |
s = regUrl.replace("%d", str(i)) | |
# 해당 웹 주소에 대한 응답을 받아온다. | |
buf = getResponseFromHTTP(s) # 분명 여기서 에러가 납니다. | |
# 여기서 나는 에러의 2가지 종류 | |
# 1. 웹툰을 긁어왔는데 해당하는 웹툰 이미지가 더이상 존재 하지 않는다. | |
# 2. 그냥 애초에 저 웹툰 이미지가 존재 하지 않는다. | |
# 서버로부터의 응답을 저장한다. | |
hFile = open(str(i) + '.jpg', 'wb') | |
hFile.write(buf) | |
hFile.close() | |
i = i + 1 | |
def main(argv): | |
# 메인 윈도우 생성. | |
mainWnd = Tk() | |
mainWnd.title("레진코믹스 크롤러") | |
mainWnd.geometry('400x200') # 창크기 설정. | |
mainWnd.resizable(0, 0) # 크기 변경 불가, 즉 원래크기/최대화 기능 안됨. | |
# 창에 보여질 객체들 생성. | |
so.txtURL = Text(mainWnd, width = 100) | |
button = Button(mainWnd, text = "가져오기", command = getURLFromTextField) # set callback function usage : command = fnc_foo. | |
# 창에 보여질 객체들 재위치. | |
so.txtURL.place(x = 0, y = 10, width = 400, height = 25) | |
button.place(x = 150, y = 40, width = 100, height = 20) | |
# 윈도우 프로시져 시작. | |
mainWnd.mainloop() | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment