Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update chrysanthemumgarden.py #2042

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions sources/en/c/chrysanthemumgarden.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from lncrawl.core.crawler import Crawler
from urllib.parse import urlparse

logger = logging.getLogger(__name__)

Expand All @@ -17,11 +18,28 @@ def read_novel_info(self):

possible_title = soup.select_one("h1.novel-title")
assert possible_title, "No novel title"
raw_title = possible_title.select_one("span")
if raw_title:
raw_title.extract()
self.novel_title = possible_title.text
logger.info("Novel title: %s", self.novel_title)

# self.novel_author = soup.select_one('.bookinfo .status').text
# logger.info('%s', self.novel_author)
novel_info = soup.select_one(".novel-info")
for e in novel_info:
if e.text.strip().startswith("Author: "):
self.novel_author = e.replace("Author: ", "").strip()
logger.info("Novel author: %s", self.novel_author)
break

# possible_synopsis = soup.select_one(".entry-content")
# if possible_synopsis:
# self.novel_synopsis = self.cleaner.extract_contents(possible_synopsis)
# logger.info("Novel synopsis: %s", self.novel_synopsis)

self.novel_tags = [
a.text.split(" (")[0].strip() for a in soup.select("a.series-tag")
]
logger.info("Novel tags: %s", self.novel_tags)

possible_image = soup.select_one(".novel-cover img")
if possible_image:
Expand All @@ -44,8 +62,24 @@ def read_novel_info(self):

self.volumes = [{"id": x, "title": ""} for x in volumes]

def login(self, email, password):
self.password = password

def download_chapter_body(self, chapter):
soup = self.get_soup(chapter["url"])

chapter_url = chapter["url"]
soup = self.get_soup(chapter_url)

if soup.select_one("#site-pass"):
payload = {
"site-pass": self.password,
"nonce-site-pass": soup.select_one("#nonce-site-pass")["value"],
"_wp_http_referer": urlparse(chapter_url).path,
}

soup = self.make_soup(
self.submit_form(url=self.absolute_url(chapter_url), data=payload),
jere344 marked this conversation as resolved.
Show resolved Hide resolved
)

bads = ["chrysanthemumgarden (dot) com", "Chrysanthemum Garden"]

Expand All @@ -59,7 +93,10 @@ def download_chapter_body(self, chapter):

text = ""
for span in p.select("span.jum"):
text += self.descramble_text(span.text) + " "
try:
text += self.descramble_text(span.text) + " "
except IndexError:
pass

if not text:
text = p.text.strip()
Expand Down