-
-
Notifications
You must be signed in to change notification settings - Fork 312
/
Copy pathnovelww.py
74 lines (59 loc) · 2.16 KB
/
novelww.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
# -*- coding: utf-8 -*-
import logging
from lncrawl.core.crawler import Crawler
logger = logging.getLogger(__name__)
class Eight88NovelCrawler(Crawler):
base_url = ["https://novelww.com/"]
has_manga = False
has_mtl = True
def read_novel_info(self):
soup = self.get_soup(self.novel_url)
self.novel_title = soup.find("h1", {"class": "crop-text-1"}).text.strip()
try:
rows = soup.find("table").find_all("tr")
self.novel_author = ", ".join(
[
e.text.strip()
for e in rows[(1 if len(rows) == 3 else 0)].find_all("a")
]
)
except Exception:
pass
try:
self.novel_cover = self.absolute_url(
soup.find("div", {"class": "book3d"}).find("img").get("data-src")
)
except Exception:
pass
self.volumes = [{"id": 1}]
self.chapters = []
chapter_count = 1
first_iteration = True
next_page = None
while next_page or first_iteration:
if first_iteration:
first_iteration = False
else:
soup = self.get_soup(next_page.get("href"))
try:
next_page = soup.find("ul", {"id": "id_pagination"}).find(
lambda tag: tag.name == "a" and tag.text == "»"
)
except AttributeError:
next_page = None
for chap in soup.find("ul", {"class": "listchap clearfix"}).find_all("a"):
if not chap.get("href"):
continue
self.chapters.append(
{
"title": self.cleaner.clean_text(chap.text),
"url": chap.get("href").strip(),
"volume": 1,
"id": chapter_count,
}
)
chapter_count += 1
def download_chapter_body(self, chapter):
soup = self.get_soup(chapter["url"])
content = soup.find("div", {"class": "reading"})
return self.cleaner.extract_contents(content)