0rx

Nhen*ai.net manga crawler

0rx
Feb 14th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.54 KB | None | 0 0
  1. # I used it to crawl pics from a hentai reading site
  2. # IDK why, but it might be usefull for someone
  3. # as it was very useful for me (Lol)
  4. # use it in moderation, perverts!
  5.  
  6.  
  7. from urllib import request as req
  8. import time
  9. import json
  10. import os
  11. import struct
  12. import gzip
  13. import io
  14. import re
  15. import sys
  16.  
  17. #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
  18.  
  19. dl = True
  20. session_name = ""
  21. gallery   = "214024" #<- you just need to change this value
  22. #getting title
  23. if True:
  24.                         pagelink = "http://nhentai.net/g/%s"% (gallery)
  25.                         reque = req.Request(pagelink, headers={'Accept-encoding':'gzip','User-Agent': 'Mozilla/5.0'})
  26.                         rawl = req.urlopen(reque)
  27.                         encoding = rawl.headers.get('Content-Encoding')
  28.                         print(encoding)
  29.                         if encoding == None:
  30.                             rawl = str(rawl.read())
  31.                         else:
  32.                             if encoding.upper() == "GZIP":
  33.                                 try:
  34.                                     compressedstream = io.BytesIO(rawl.read())
  35.                                     gzipper = gzip.GzipFile(fileobj=compressedstream)
  36.                                     rawl = str(gzipper.read())
  37.                                 except Exception as exc:
  38.                                     print(exc)
  39. #                        rawl = str(req.urlopen(pagelink).read())
  40.                         #print(rawl)
  41.                         rawl2 = rawl.split("\n")
  42.                         rawl_list = []
  43.                         for li in rawl2:
  44.                           x = li.split(">")
  45.                           for xx in x:
  46.                             rawl_list.append(xx)
  47.                         #print(rawl_list)
  48.                         title=rawl_list[5].split('content="')
  49.                         title=title[1].split('" /')
  50.                         series=title[0]
  51.                         print(series)
  52.  
  53. destination = "pig/%s-%s/"%(series,gallery)
  54.  
  55. def downloop():
  56.   while dl == True:
  57.    try:
  58.     session_name = "%s-%s"%(series,gallery)
  59.     try:
  60.         os.mkdir(destination)
  61.     except:
  62.         pass
  63.     for page in range(1,500):
  64.                 checklist = os.listdir(destination)
  65.                 if len(str(page)) == 1:
  66.                     pagenum = "00"+str(page)
  67.                 if len(str(page)) == 2:
  68.                     pagenum = "0"+str(page)
  69.                 if pagenum+".jpg" in checklist:
  70.                         print(pagenum+".jpg Checked.")
  71.                        
  72.                         pass
  73.                 if pagenum+".jpg" not in checklist:
  74.                         pagelink = "http://nhentai.net/g/%s/%s"% (gallery, page)
  75.                         reque = req.Request(pagelink, headers={'Accept-encoding':'gzip','User-Agent': 'Mozilla/5.0'})
  76.                         rawl = req.urlopen(reque)
  77.                         encoding = rawl.headers.get('Content-Encoding')
  78.                         print(encoding)
  79.                         if encoding == None:
  80.                             rawl = str(rawl.read())
  81.                         else:
  82.                             if encoding.upper() == "GZIP":
  83.                                 try:
  84.                                     compressedstream = io.BytesIO(rawl.read())
  85.                                     gzipper = gzip.GzipFile(fileobj=compressedstream)
  86.                                     rawl = str(gzipper.read())
  87.                                 except Exception as exc:
  88.                                     print(exc)
  89.                         rawl2 = rawl.split("\\")
  90.                         rawl_list = []
  91.                         for li in rawl2:
  92.                           x = li.split("t<img ")
  93.                           for xx in x:
  94.                             rawl_list.append(xx)
  95.                         last_list = []
  96.                         for i in rawl_list:
  97.                             if 'src="https://i.nhentai.net/galleries/' in i:
  98.                                 last_list.append(i)
  99.                         last_link = last_list[0].split('"')
  100.                         last = last_link[1]
  101.                         print(last)
  102.                         req.urlretrieve(last, "%s%s.jpg"%(destination, pagenum))
  103.                         print(pagenum+".jpg is done")
  104.    except Exception as ex:
  105.          print(ex)
  106.          print(series)
  107.          break
  108. downloop()
  109. print(session_name + " Done.")
Add Comment
Please, Sign In to add comment