-
-
Notifications
You must be signed in to change notification settings - Fork 312
/
Copy pathsoxs.py
55 lines (43 loc) · 1.88 KB
/
soxs.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
# -*- coding: utf-8 -*-
import logging
from lncrawl.core.crawler import Crawler
logger = logging.getLogger(__name__)
class Soxc(Crawler):
base_url = ["https://www.soxs.cc/"]
def read_novel_info(self):
self.novel_url = self.novel_url.replace("/book/", "/")
self.novel_url = self.novel_url.replace(".html", "/")
soup = self.get_soup(self.novel_url)
possible_title = soup.select_one(".xiaoshuo h1")
assert possible_title, "No novel title"
self.novel_title = possible_title.get_text()
logger.info(f"Novel title: {self.novel_title}")
self.novel_author = soup.select_one(".xiaoshuo h6").get_text()
logger.info(f"Novel Author: {self.novel_author}")
possible_novel_cover = soup.select_one(".book_cover img")
if possible_novel_cover:
self.novel_cover = self.absolute_url(possible_novel_cover["src"])
logger.info(f"Novel Cover: {self.novel_cover}")
logger.info("Getting chapters...")
for chapter in soup.select(".novel_list dd a"):
url = self.absolute_url(chapter["href"])
chap_id = len(self.chapters) + 1
if len(self.chapters) % 100 == 0:
vol_id = len(self.chapters) // 100 + 1
self.volumes.append({"id": vol_id})
self.chapters.append(
{
"id": chap_id,
"url": url,
"volume": vol_id,
}
)
def download_chapter_body(self, chapter):
soup = self.get_soup(chapter["url"])
title = soup.select_one(".read_title h1").text.strip()
chapter["title"] = title
content = soup.select(".content")
content = "\n".join(str(p) for p in content)
content = content.replace(self.novel_url, "")
content = content.replace("soxscc", "mtlrealm.com ")
return content