Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I used it to crawl pics from a hentai reading site
- # IDK why, but it might be usefull for someone
- # as it was very useful for me (Lol)
- # use it in moderation, perverts!
- from urllib import request as req
- import time
- import json
- import os
- import struct
- import gzip
- import io
- import re
- import sys
- #https://nhentai.net/g/92405/6/ <- this is a link to a random hentai manga gallery, you need to replace the value of gallery with "92405" to exactly download manga from this link
- dl = True
- session_name = ""
- gallery = "214024" #<- you just need to change this value
- #getting title
- if True:
- pagelink = "http://nhentai.net/g/%s"% (gallery)
- reque = req.Request(pagelink, headers={'Accept-encoding':'gzip','User-Agent': 'Mozilla/5.0'})
- rawl = req.urlopen(reque)
- encoding = rawl.headers.get('Content-Encoding')
- print(encoding)
- if encoding == None:
- rawl = str(rawl.read())
- else:
- if encoding.upper() == "GZIP":
- try:
- compressedstream = io.BytesIO(rawl.read())
- gzipper = gzip.GzipFile(fileobj=compressedstream)
- rawl = str(gzipper.read())
- except Exception as exc:
- print(exc)
- # rawl = str(req.urlopen(pagelink).read())
- #print(rawl)
- rawl2 = rawl.split("\n")
- rawl_list = []
- for li in rawl2:
- x = li.split(">")
- for xx in x:
- rawl_list.append(xx)
- #print(rawl_list)
- title=rawl_list[5].split('content="')
- title=title[1].split('" /')
- series=title[0]
- print(series)
- destination = "pig/%s-%s/"%(series,gallery)
- def downloop():
- while dl == True:
- try:
- session_name = "%s-%s"%(series,gallery)
- try:
- os.mkdir(destination)
- except:
- pass
- for page in range(1,500):
- checklist = os.listdir(destination)
- if len(str(page)) == 1:
- pagenum = "00"+str(page)
- if len(str(page)) == 2:
- pagenum = "0"+str(page)
- if pagenum+".jpg" in checklist:
- print(pagenum+".jpg Checked.")
- pass
- if pagenum+".jpg" not in checklist:
- pagelink = "http://nhentai.net/g/%s/%s"% (gallery, page)
- reque = req.Request(pagelink, headers={'Accept-encoding':'gzip','User-Agent': 'Mozilla/5.0'})
- rawl = req.urlopen(reque)
- encoding = rawl.headers.get('Content-Encoding')
- print(encoding)
- if encoding == None:
- rawl = str(rawl.read())
- else:
- if encoding.upper() == "GZIP":
- try:
- compressedstream = io.BytesIO(rawl.read())
- gzipper = gzip.GzipFile(fileobj=compressedstream)
- rawl = str(gzipper.read())
- except Exception as exc:
- print(exc)
- rawl2 = rawl.split("\\")
- rawl_list = []
- for li in rawl2:
- x = li.split("t<img ")
- for xx in x:
- rawl_list.append(xx)
- last_list = []
- for i in rawl_list:
- if 'src="https://i.nhentai.net/galleries/' in i:
- last_list.append(i)
- last_link = last_list[0].split('"')
- last = last_link[1]
- print(last)
- req.urlretrieve(last, "%s%s.jpg"%(destination, pagenum))
- print(pagenum+".jpg is done")
- except Exception as ex:
- print(ex)
- print(series)
- break
- downloop()
- print(session_name + " Done.")
Add Comment
Please, Sign In to add comment