Advertisement
xah

KKmanhua v0.0.0

xah
Feb 26th, 2017 (edited)
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. #This is xah's crappy code for extracting images off KuaiKanManhua.com
  2. #It's the crappiest thing ever, I know, but it (sort of) works!!
  3.  
  4. import requests, os, bs4, re
  5.  
  6. print("""This code extracts the images off KuaiKanManhua.com.
  7. Note, this program saves files as:
  8.   prefix + number + .jpg
  9. The prefix can be defined by you.
  10. The folder name can be defined by you.
  11. (The folder will be where this program is saved at.) \n\n""")
  12. prefix = input('Please input a prefix: ')
  13. folder = input('Please input a folder name: ')
  14. url = input('Please input the url of the KuaiKanManhua chapter: ')
  15.  
  16. os.makedirs(folder, exist_ok=True)
  17.  
  18. res = requests.get(url)
  19. res.raise_for_status()
  20.  
  21. #parsing the file / extracting file
  22. soup = bs4.BeautifulSoup(res.text, 'html.parser')
  23. comicElem = soup.select('img[data-kksrc]')
  24. comicElem = str(comicElem)
  25.  
  26. searcher = re.compile(r'data-kksrc="(.*?)"')
  27. comicUrl = searcher.findall(comicElem)
  28.  
  29. loop = '001'
  30.  
  31. for i in comicUrl:
  32.     #Because of the weird loop kkmanhua has...
  33.     if i in comicUrl[:int(loop) - 1]:
  34.         break
  35.    
  36.     #Writing the image
  37.     print('Downloading page %s...' % i)
  38.     imageFile = open(os.path.join(folder, os.path.basename(prefix + loop + '.png')), 'wb')
  39.     imageFile.write(requests.get(i).content)
  40.     imageFile.close()
  41.  
  42.     #For better naming reasons
  43.     loop = int(loop) + 1
  44.    
  45.     if  loop < 10:
  46.         loop = '00' + str(loop)
  47.  
  48.     elif loop < 100:
  49.         loop = '0' + str(loop)
  50.  
  51.     else:
  52.         loop = str(loop)
  53.  
  54. #finding next chapter
  55. nextCh = soup.select('a[title="???"]')
  56. nextCh = str(comicElem)
  57.  
  58. print('Done')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement