Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import os
- from re import finditer
- headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) But it's actually python cuz i'm bored"}
- def html_get(url):
- r = requests.get(url, headers=headers)
- return r.text
- search_name = input("Name of manga : ")
- search_html = html_get("http://mangakakalot.com/search/" + search_name.replace(' ', '_'))
- found_iter = finditer('item-name', search_html)
- links = []
- for iteration in found_iter:
- index = iteration.start() + 21
- url = ""
- while search_html[index] != '"':
- url += search_html[index]
- index += 1
- links.append(url)
- if len(links) == 0:
- print("None of that name found")
- input("Press Enter to exit")
- exit()
- for i, url in enumerate(links):
- print("{} : {}".format(i + 1, url.replace("_", " ")[30:]))
- user_input = int(input("Which one is the correct one? [1 : {}] : ".format(len(links))))
- #print(user_input)
- #print(links[user_input - 1])
- url_link = links[user_input - 1]
- manga_name = links[user_input - 1].replace("_", " ")[30:].title()
- if not os.path.exists(manga_name):
- os.makedirs(manga_name)
- os.chdir(manga_name)
- #url_link = input("Link to the manga [mangakakalot.com / manganelo.com source] : ")
- chapter_link = url_link[::-1].replace('/agnam/', '/retpahc/', 1)[::-1]
- html = html_get(url_link)
- index = html.find('div class="row">')
- html = html[index:]
- #print(chapter_link)
- found_iter = finditer(chapter_link, html)
- chapter_links = []
- for iteration in found_iter:
- index = iteration.start() + len(chapter_link)
- url = chapter_link
- while html[index] != '"':
- url += html[index]
- index += 1
- #print(url)
- chapter_links.append(url)
- chapter_links = list(reversed(chapter_links))
- print("Preparations complete")
- print("Chapters like 2.5 count as one just so you know")
- print("But the folders' chapter number will be fitting to the chapter")
- f_ch = int(input("From Chapter [{} is Last] : ".format(len(chapter_links))))
- t_ch = int(input("Till Chapter : "))
- for i in range(f_ch, t_ch + 1):
- ch_link = chapter_links[i - 1]
- html = html_get(ch_link)
- index = html.find('<div class="vung-doc" id="vungdoc">')
- index = html.find('1.jpg', index) - 1
- sub_url = ""
- while html[index] != '"':
- sub_url += html[index]
- index -= 1
- sub_url = sub_url[::-1]
- Chapter_name = chapter_links[i-1][len(chapter_link) + 1:].replace("_", " ").title()
- if not os.path.exists("{}".format(Chapter_name)):
- os.makedirs("{}".format(Chapter_name))
- os.chdir("{}".format(Chapter_name))
- nr = 1
- s = 2
- while True:
- r = requests.get("{}{}.jpg".format(sub_url, nr), headers=headers)
- if r.status_code == 404:
- break
- with open("{}{}.jpg".format("0" * s, nr), "wb") as img_obj:
- img_obj.write(r.content)
- print("Done with {} Page {}".format(Chapter_name, nr))
- nr += 1
- if nr == 10 or nr == 100:
- s -= 1
- os.chdir("..")
- input("Done\a")
Add Comment
Please, Sign In to add comment