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

Fix source #2147

Merged
merged 1 commit into from
Sep 29, 2023
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
31 changes: 20 additions & 11 deletions sources/en/h/hostednovel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
class HostedNovelCom(Crawler):
base_url = 'https://hostednovel.com/'

def extract_numbers_from_string(self, input_string):
# Define a regular expression pattern to match numbers (integers and decimals)
pattern = r"[-+]?\d*\.\d+|\d+"

# Use the findall() method to extract all matching numbers from the input string
numbers = re.findall(pattern, input_string)

# Convert the matched strings to actual numbers (float or int)
numbers = [float(number) if '.' in number else int(number) for number in numbers]

return numbers

def read_novel_info(self):
soup = self.get_soup(self.novel_url)

Expand All @@ -34,19 +46,16 @@ def read_novel_info(self):

logger.info('Novel author: %s', self.novel_author)

page_re = re.compile(r'page=(\d+)#chapters')
final_page = max([
int(page[0])
for page in [
page_re.findall(a['href'])
for a in soup.select('#chapters nav[aria-label="Pagination"] a')
if a.has_attr('href')
] if len(page) == 1
])

if soup.select_one('#chapters nav[aria-label="Pagination"] a:nth-last-child(1)'):
final_pg = soup.select_one('#chapters nav[aria-label="Pagination"] a:nth-last-child(1)')
logger.info(f'max_page = {self.extract_numbers_from_string(final_pg["href"])[0]}')
final_pg = self.extract_numbers_from_string(final_pg["href"])[0]
else:
final_pg = 1
logger.info(f'max_page = {final_pg}')
futures = []
raw_novel_url = re.split(r'[?#]', self.novel_url)[0]
for page in range(final_page):
for page in range(final_pg):
page_url = raw_novel_url + f'?page={page + 1}'
logger.info('Getting chapters from "%s"', page_url)
f = self.executor.submit(self.get_soup, page_url)
Expand Down