Редактор для EPUB
https://sigil-ebook.com/sigil/download/

Для win7
https://github.com/Sigil-Ebook/Sigil/releases/tag/1.9.30

#pip install googletrans==3.1.0a0
from googletrans import Translator
from ebooklib import epub, utils
from bs4 import BeautifulSoup, NavigableString
import lxml.html as html

def test():
    #какие теги исключить
    tag_exeption = ["code", 'a', 'strong', 'pre', 'span', 'html', 'div', 'body', "head"]

    book = epub.read_epub('3D Printing Failures_ 2022 Edition.epub')

    for item in book.get_items():
        # print(item.get_id())
        if item.get_id() == "id_3":
            print('NAME : ', item.get_name())
            print('----------------------------------')
            print('ID : ', item.get_id())
            print('----------------------------------')
            print('ITEM : ', item.get_type())
            print('----------------------------------')
            print((item.get_content()))
            print('----------------------------------')

            soup = BeautifulSoup(item.get_content(), features="xml")
            print(soup)
            print('----------------------------------')

            for child in soup.descendants:
                # print(child.name)
                if child.name not in tag_exeption and child.name and child.string:
                    #print(child.string)

                    translator = Translator()
                    result = translator.translate(child.string, dest='ru').text

                    print(result)

if __name__ == "__main__":
    test()
Нет комментариев.