Skip to content

Instantly share code, notes, and snippets.

@kyujin-cho
Created September 11, 2017 04:18
Show Gist options
  • Save kyujin-cho/d1807e7743f17f6860cea74db6f2cd0e to your computer and use it in GitHub Desktop.
Save kyujin-cho/d1807e7743f17f6860cea74db6f2cd0e to your computer and use it in GitHub Desktop.
Download naver webtoon
import urllib.request
from bs4 import BeautifulSoup as BSoup
import sys
import os
import os.path
id, no = sys.argv[1], sys.argv[2]
base_url = 'http://comic.naver.com/webtoon/detail.nhn?titleId={}&no={}'.format(id, no)
folder_name = 'webtoon_' + id + '_' + no
html = urllib.request.urlopen(base_url).read()
soup = BSoup(html.decode('utf-8'))
viewer = soup.find('div', {'class' : 'wt_viewer'})
print(viewer)
if not os.path.isdir(folder_name):
os.mkdir(folder_name)
images = viewer.find_all('img')
i = 1
for image in images:
print(image['src'])
download = urllib.request.Request(image['src'])
download.add_header('Referer', base_url)
res = urllib.request.urlopen(download)
with open(folder_name + '/' + str(i) + '.jpg', 'wb') as f:
f.write(res.read())
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment