This repository has been archived on 2024-02-23. You can view files and clone it, but cannot push or open issues or pull requests.
Auberge_Vagabonde/livres_fr.py
2021-04-10 23:53:47 +02:00

52 lines
1.2 KiB
Python

import os
import requests
from bs4 import BeautifulSoup
from pypub import Epub, create_chapter_from_string
if not os.path.exists('output'):
os.makedirs('output')
post = 0
volumes = [
None,
Epub("L'auberge Vagabonde - Volume 1", cover='cover.png'),
Epub("L'auberge Vagabonde - Volume 2", cover='cover.png')
]
for page in range(12):
html = requests.get(
'https://www.jeunesecrivains.com/t53075p%s-the-wandering-inn-fan-traduction-fantastique-aventure' % (page * 15))
soup = BeautifulSoup(html.text, 'html.parser')
tags = soup.select('div.postbody')
for tag in tags:
post = post + 1
volume = 1 if post <= 69 else 2
if post == 1:
continue
title_test = tag.div.select_one('div[align=center]')
if not title_test:
continue
title = title_test.contents[0]
title_test.decompose()
text = tag.div.div
if text.get_text() == '':
text = tag.div
del text['style']
print(title)
chapter = create_chapter_from_string(str(text), title)
volumes[volume].add_chapter(chapter)
volumes[1].create_epub('output')
volumes[2].create_epub('output')