-
-
Notifications
You must be signed in to change notification settings - Fork 305
/
chireads.py
92 lines (74 loc) · 2.8 KB
/
chireads.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
88
89
90
91
92
# -*- coding: utf-8 -*-
import logging
import requests
from lncrawl.core.crawler import Crawler
logger = logging.getLogger(__name__)
class Chireads(Crawler):
base_url = ["https://chireads.com/"]
has_manga = False
has_mtl = False
def search_novel(self, query):
query = query.lower().replace(" ", "+")
# NOTE: Using self.get_soup() here throw an error, I don't know why.
response = requests.get("https://chireads.com/search?x=0&y=0&name=" + query)
soup = self.make_soup(response)
result = []
content = soup.find("div", {"id": "content"})
for novel in content.find_all("li"):
content = novel.find("a")
result.append(
{
"title": content.get("title"),
"url": self.absolute_url(content.get("href")),
}
)
return result
def read_novel_info(self):
soup = self.get_soup(self.novel_url)
content = soup.find("div", {"class": "conteiner"}).find_all(
"div", {"class": "wid"}
)
metadata = content[0]
self.novel_synopsis = self.cleaner.extract_contents(
metadata.find("div", {"class": "inform-txt-show font-color-black6"})
)
for tag in soup.select("div.lable-list a"):
self.novel_tags.append(tag.text)
self.novel_cover = self.absolute_url(metadata.find("img").get("src"))
self.novel_title = (
metadata.find("h3", {"class": "inform-title"}).text.split("|")[0].strip()
)
self.novel_author = (
metadata.find("h6", {"class": "font-color-black3"})
.text.split("\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0")[0]
.replace("Auteur : ", "")
)
body = content[1]
tomes = body.find_all("div", {"class": "chapitre"})
for vol_id, tome in enumerate(tomes, 1):
self.volumes.append(
{
"id": vol_id,
"title": tome.find("div", {"class": "title"}).text,
}
)
for chapter in tome.find_all("a"):
chap_id = len(self.chapters) + 1
self.chapters.append(
{
"id": chap_id,
"volume": vol_id,
"url": self.absolute_url(chapter.get("href")),
"title": chapter.text.replace("\xa0", " "),
}
)
def download_chapter_body(self, chapter):
soup = self.get_soup(chapter["url"])
content = soup.find(
"div",
{
"id": "content",
"class": "font-color-black3 article-font",
},
)
return self.cleaner.extract_contents(content)