-
-
Notifications
You must be signed in to change notification settings - Fork 305
/
koreanmtl.py
65 lines (56 loc) · 2.34 KB
/
koreanmtl.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
# -*- coding: utf-8 -*-
import re
import logging
from lncrawl.core.crawler import Crawler
logger = logging.getLogger(__name__)
class LightNovelsOnl(Crawler):
has_mtl = True
base_url = "https://www.koreanmtl.online/"
def initialize(self) -> None:
self.init_parser("html5lib")
def read_novel_info(self):
logger.debug("Visiting %s", self.novel_url)
soup = self.get_soup(self.novel_url)
# self.novel_title = soup.select_one('h1.entry-title').text.strip()
possible_title = soup.select_one(".post-title.entry-title")
assert possible_title, "No novel title"
self.novel_title = possible_title.text.strip()
logger.info("Novel title: %s", self.novel_title)
volumes = set([])
for a in soup.select(".post-body.entry-content ul li a"):
chap_id = 1 + len(self.chapters)
vol_id = 1 + len(self.chapters) // 100
volumes.add(vol_id)
self.chapters.append(
{
"id": chap_id,
"volume": vol_id,
"title": a.text.strip(),
"url": self.absolute_url(a["href"]),
}
)
self.volumes = [{"id": x} for x in volumes]
def download_chapter_body(self, chapter):
soup = self.get_soup(chapter["url"])
contents = soup.select_one(".post-body.entry-content")
for el in contents.select('div[style="text-align:center;"]'):
el.extract()
body = ""
for p in contents.select("p"):
line = p.text.strip()
line = re.sub(r"<", "<", line)
line = re.sub(r">", ">", line)
line = re.sub(r"\u3008", "<", line)
line = re.sub(r"\u3009", ">", line)
line = re.sub(r"\uff08", "(", line)
line = re.sub(r"\uff09", ")", line)
line = re.sub(r"\uff0c", ",", line)
line = re.sub(r"\u2026", "...", line)
line = re.sub(r"\uff1e", ">", line)
line = re.sub(r"\u200b", " ", line)
line = re.sub(r"\u3001", "`", line)
line = re.sub(r"(\(\))|(\[\])", "", line)
# line = re.sub(r'([\u00FF-\uFFFF])', lambda m: '&#x%d;' % ord(m.group(1)), line)
if re.search(r"[\w\d]", line):
body += "<p>" + line + "</p>"
return body