-
-
Notifications
You must be signed in to change notification settings - Fork 284
/
aixdzs.py
62 lines (48 loc) · 2.13 KB
/
aixdzs.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
# -*- coding: utf-8 -*-
import logging
from lncrawl.core.crawler import Crawler
logger = logging.getLogger(__name__)
chapter_list_url = "https://read.aixdzs.com/%s"
class AixdzsCrawler(Crawler):
base_url = "https://www.aixdzs.com"
def read_novel_info(self):
if not self.novel_url.endswith("/"):
self.novel_url += "/"
logger.debug("Visiting %s", self.novel_url)
soup = self.get_soup(self.novel_url)
possible_title = soup.select_one(".fdl .d_info h1")
assert possible_title, "No novel title"
self.novel_title = possible_title.text.strip()
logger.info("Novel title: %s", self.novel_title)
possible_novel_cover = soup.select_one('meta[property="og:image"]')
if possible_novel_cover:
self.novel_cover = self.absolute_url(possible_novel_cover["content"])
logger.info("Novel cover: %s", self.novel_cover)
possible_novel_author = soup.select_one('meta[property="og:novel:author"]')
if possible_novel_author:
self.novel_author = possible_novel_author["content"]
logger.info("%s", self.novel_author)
# parsed_url = urlparse(self.novel_url)
# parsed_path = parsed_url.path.strip('/').split('/')
# chapter_url = chapter_list_url % ('/'.join(parsed_path[1:]))
# logger.debug('Visiting %s', chapter_url)
# soup = self.get_soup(chapter_url)
volumes = set([])
for a in soup.select("div.catalog li a"):
ch_id = len(self.chapters) + 1
vol_id = 1 + len(self.chapters) // 100
volumes.add(vol_id)
self.chapters.append(
{
"id": ch_id,
"volume": vol_id,
"title": a.text,
"url": self.absolute_url(a["href"]),
}
)
self.volumes = [{"id": x, "title": ""} for x in volumes]
def download_chapter_body(self, chapter):
soup = self.get_soup(chapter["url"])
contents = soup.select(".content > p")
contents = [str(p) for p in contents if p.text.strip()]
return "".join(contents)