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 url = 'https://www.jeunesecrivains.com/t53075p%s-the-wandering-inn-fan-traduction-fantastique-aventure' volumes = [ None, Epub("L'auberge Vagabonde - Volume 1", creator='Maroti, ElliVia', rights='Pirateaba', language='fr', cover='cover.png'), Epub("L'auberge Vagabonde - Volume 2", creator='Maroti, ElliVia', rights='Pirateaba', language='fr', cover='cover.png') ] for page in range(12): html = requests.get(url % (page * 15)) soup = BeautifulSoup(html.text, 'html.parser') tags = soup.select('div.postbody') for tag in tags: post = post + 1 if post <= 69: volume = 1 elif post <= 168: volume = 2 else: volume = 3 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(str(post) + ' - ' + title) chapter = create_chapter_from_string(str(text), title) volumes[volume].add_chapter(chapter) volumes[1].create_epub('output') volumes[2].create_epub('output')