-
Notifications
You must be signed in to change notification settings - Fork 1
/
mangascrapper.py
87 lines (87 loc) · 3.09 KB
/
mangascrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from selenium import webdriver
import os
import time
import zipfile
from fpdf import FPDF
from chdrv import chromedriver
chrome_options = webdriver.ChromeOptions()
prefs = {'download.default_directory': os.getcwd()}
chrome_options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(chromedriver, chrome_options=chrome_options)
manga = input("Enter the name of Manga to search - ").lower()
manga = manga.split()
driver.get("http://www8.mangafreak.net/Search/" + '%20'.join(manga))
while (1):
try:
done = driver.find_element_by_link_text("Home")
break
except Exception as e:
time.sleep(1)
continue
result = driver.find_elements_by_class_name("manga_search_item")
for r in result:
print(r.text)
index = int(input("Enter Index of anime to proceed - "))
index-=1
interest = result[index]
link = interest.find_element_by_tag_name("a")
link.click()
lists = driver.find_element_by_class_name("manga_series_list")
chap = lists.find_elements_by_tag_name("tr")
for index, val in enumerate(chap):
print(index, "\t=>\t", val.text)
i = int(input("Which index chapter do you want to download? (zero if a range is needed) "))
if i != 0:
interest = chap[i]
print( "Downloading ", interest.find_elements_by_tag_name("td")[0].text)
down = interest.find_element_by_link_text("Download").click()
else:
print("Enter range of chapters to download (inclusive)")
start = int(input("start = "))
end = int(input("end = "))
for i in range(start, end + 1):
interest = chap[i]
down = interest.find_element_by_link_text("Download").click()
print(" Downloading ", interest.find_elements_by_tag_name("td")[0].text)
time.sleep(1)
driver.get('chrome://downloads')
while True:
for item in driver.find_elements_by_css_selector('body/deep/downloads-item'):
if 'pause' in item.text.lower():
time.sleep(2)
break
else:
break
def natural_keys(text):
c = text.split(".")[0].split('_')[-1]
return int(c)
listFiles = []
cwd = os.getcwd()
for file in os.listdir(cwd):
if file.endswith(".zip"):
listFiles.insert(1, str(file))
listFiles.sort(key=natural_keys)
for file in listFiles:
path = file.split('.')[0]
try:
os.mkdir(path)
except OSError:
print ("Creation of the directory %s failed" % path)
else:
try:
zip_ref = zipfile.ZipFile(os.path.join(cwd, file), 'r')
zip_ref.extractall(path)
zip_ref.close()
mypath = os.path.join(cwd,path)
onlyfiles = [f for f in os.listdir(mypath) if os.path.isfile(os.path.join(mypath, f))]
def natural_keys_1(text):
c = text.split(".")[0].split('_')[-1]
return int(c)
onlyfiles.sort(key=natural_keys_1)
pdf = FPDF()
for image in onlyfiles:
pdf.add_page()
pdf.image(mypath + '/' + image, 0, 0, w=210, h=297)
pdf.output(file.split('.')[0] + ".pdf", "F")
except:
continue