Skip to content

Commit

Permalink
v4
Browse files Browse the repository at this point in the history
확장자가 png로 고정되지 않고 올려진 웹툰 이미지 파일 확장자에 따라 저장됨.
  • Loading branch information
pgh268400 authored Aug 5, 2021
1 parent 9e9c9d7 commit 35c6f3b
Showing 1 changed file with 13 additions and 32 deletions.
45 changes: 13 additions & 32 deletions NWebtoon.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#!/usr/bin/env python
# coding: utf-8

# In[ ]:


# -*- coding: utf-8 -*-
import requests
import os, errno, glob
Expand All @@ -16,6 +10,9 @@
from sys import exit
from datetime import datetime
from time import sleep
from urllib import parse


download_index = 1
NID_AUT = ''
NID_SES = ''
Expand All @@ -36,29 +33,19 @@ def filename_remover(string):
string = string.replace(str_, "")
return string


# In[ ]:


def tag_remover(string):
cleaner = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});') #<tag>, &nbfs 등등 제거
string = re.sub(cleaner, '', string)
return string


# In[ ]:


def image_download(url, file_name):
with open(file_name, "wb") as file: # open in binary mode
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36', 'host' : 'image-comic.pstatic.net'}
response = get(url,headers = headers) # get request
file.write(response.content) # write to file


# In[ ]:


# 단일 이미지 다운로드
def single_download(id, args, type_):
print(args,'화 다운로드 시작되었습니다')
Expand All @@ -79,16 +66,17 @@ def single_download(id, args, type_):
j=0
for img in image_url:
url = img['src']
_path = path + "\\" + str(j) + '.png'

parsed = parse.urlparse(url)
name, ext = os.path.splitext(parsed.path)

_path = path + "\\" + str(j) + ext
image_download(url, _path)
j += 1
print(url)
input('다운로드가 완료되었습니다.')


# In[ ]:


# 이미지 링크 추출(경로 포함)
def get_image_link(id, args, type_):
global download_index, NID_AUT, NID_SES
Expand All @@ -115,17 +103,17 @@ def get_image_link(id, args, type_):
j=0
for img in image_url:
url = img['src']
_path = path + "\\" + str(j) + '.png'

parsed = parse.urlparse(url)
name, ext = os.path.splitext(parsed.path)
_path = path + "\\" + str(j) + ext

if not 'img-ctguide-white.png' in url: #컷툰이미지 제거하기
result.append([url,tag_remover(_path)]) #URL,PATH 형식으로 List에 저장
j += 1
download_index = download_index + 1
return result


# In[ ]:


#다중 이미지 다운로드
def p_image_download(data):
#참고 : 이미지서버 자체는 로그인 여부 판단안함.
Expand Down Expand Up @@ -153,10 +141,6 @@ def p_image_download(data):

break


# In[ ]:


class nwebtoon:
def __init__(self, query):
exp = '[0-9]{5,6}'
Expand Down Expand Up @@ -211,9 +195,6 @@ def search(self, keyword):
return title_id


# In[ ]:


dialog = input('모드를 선택해주세요 d : 다운로드 , m : 이미지합치기 : ')
if dialog.lower() == 'd':

Expand Down

0 comments on commit 35c6f3b

Please sign in to comment.