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

freewebnovel add new mirror & remove self-promo #2281

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Changes from all 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
12 changes: 11 additions & 1 deletion sources/en/f/freewebnovel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import unicodedata
import re

from bs4 import BeautifulSoup, Tag

Expand All @@ -14,7 +15,8 @@ class FreeWebNovelCrawler(SearchableSoupTemplate, ChapterOnlySoupTemplate):
"https://bednovel.com/",
"https://innread.com/",
"https://innnovel.com/",
"https://libread.com/"
"https://libread.com/",
"https://libread.org/",
]

def initialize(self) -> None:
Expand Down Expand Up @@ -99,8 +101,16 @@ def normalize_text(self, text: str) -> str:

def select_chapter_body(self, soup: BeautifulSoup) -> Tag:
body_tag = soup.select_one(".m-read .txt")
# style element on page that hides usually last paragraph which contains randomised self-promo text
has_promo = soup.find("style", text=re.compile("p:nth-last-child\\(\\d\\)"))
if body_tag:
normalized_body = self.normalize_text(str(body_tag))
normalized_soup = BeautifulSoup(normalized_body, "html.parser")
if has_promo:
# get index out of css selector and manually remove it via decompose
idx = int(re.match(re.compile(".+p:nth-last-child\\((\\d)\\).+"), has_promo.text)[1])
random_self_promo = normalized_soup.find_all("p")[-idx]
if isinstance(random_self_promo, Tag):
random_self_promo.decompose()
return normalized_soup
return body_tag
Loading