Dies ist eine professionelle Lösung zum Komprimieren von HTML mit Python. Verwenden Sie unsere HTML Optimierungs API, um hochwertige, plattformunabhängige Software in Python zu entwickeln. Probieren Sie es kostenlos online aus!
Verkleinern Sie große HTML Dateien ohne Qualitätsverlust. Löschen Sie unnötige und ungenutzte Daten. Verkleinern Sie die Größe einer HTML-Datei im Code. Die Python-Bibliothek bietet Entwicklern eine integrierte API zur Optimierung von HTML-Inhalten.
Die Python-Bibliothek ist eine eigenständige Lösung und erfordert keine Installation von Software von Drittanbietern.
Verlustfreie Komprimierung und umfassende Inhaltsoptimierung leicht gemacht mit 'Aspose.Words for Python via .NET'. Das folgende Beispiel zeigt, wie der Inhalt einer HTML-Datei in Python optimiert wird:
pip install aspose-words Kopieren import aspose.words as aw doc = aw.Document("Input.html") doc.cleanup() shapes = [node.as_shape() for node in doc.get_child_nodes(aw.NodeType.SHAPE, True)] for shape in shapes: if shape.isImage: # Es ist Sache des Entwicklers, die Bibliothek für die Bildkomprimierung auszuwählen. image = Image.open(shape.image_data.to_stream()) # ... # Bild komprimieren und auf die Form zurücksetzen. shape.image_data.set_image("yourCompressedImage") doc.save("Output.html") import aspose.words as aw doc = aw.Document("Input.html") doc.cleanup() shapes = [node.as_shape() for node in doc.get_child_nodes(aw.NodeType.SHAPE, True)] for shape in shapes: if shape.isImage: # Es ist Sache des Entwicklers, die Bibliothek für die Bildkomprimierung auszuwählen. image = Image.open(shape.image_data.to_stream()) # ... # Bild komprimieren und auf die Form zurücksetzen. shape.image_data.set_image("yourCompressedImage") save_options = aw.saving.PdfSaveOptions save_options.cache_background_graphics = true doc.save("Output.html", save_options) import aspose.words as aw doc = aw.Document("Input.html") doc.cleanup() shapes = [node.as_shape() for node in doc.get_child_nodes(aw.NodeType.SHAPE, True)] for shape in shapes: if shape.isImage: # Es ist Sache des Entwicklers, die Bibliothek für die Bildkomprimierung auszuwählen. image = Image.open(shape.image_data.to_stream()) # ... # Bild komprimieren und auf die Form zurücksetzen. shape.image_data.set_image("yourCompressedImage") doc.save("Output.html") import aspose.words as aw doc = aw.Document("Input.html") doc.cleanup() shapes = [node.as_shape() for node in doc.get_child_nodes(aw.NodeType.SHAPE, True)] for shape in shapes: if shape.isImage: # Es ist Sache des Entwicklers, die Bibliothek für die Bildkomprimierung auszuwählen. image = Image.open(shape.image_data.to_stream()) # ... # Bild komprimieren und auf die Form zurücksetzen. shape.image_data.set_image("yourCompressedImage") save_options = aw.saving.OoxmlSaveOptions save_options.compression_level = aw.saving.CompressionLevel.MAXIMUM doc.save("Output.html", save_options) import aspose.words as aw doc = aw.Document() builder = aw.DocumentBuilder(doc) shape = builder.InsertImage("Input.html") save_options = aw.saving.ImageSaveOptions(aw.SaveFormat.HTML) shape.get_shape_renderer().save("Output.html", save_options) import aspose.words as aw renderer = aw.pdf2word.fixedformats.PdfFixedRenderer() pdf_read_options = aw.pdf2word.fixedformats.PdfFixedOptions() pdf_read_options.image_format = aw.pdf2word.fixedformats.FixedImageFormat.JPEG pdf_read_options.jpeg_quality = 50 with open ("Input.html", 'rb') as pdf_stream: pages_stream = renderer.save_pdf_as_images(pdf_stream, pdf_read_options); builder = aw.DocumentBuilder() for i in range(0, len(pages_stream)): # Legen Sie die maximale Seitengröße fest, um die aktuelle Seitenbildskalierung zu vermeiden. max_page_dimension = 1584 page_setup = builder.page_setup set_page_size(page_setup, max_page_dimension, max_page_dimension) page_image = builder.insert_image(pages_stream[i]) set_page_size(page_setup, page_image.width, page_image.height) page_setup.top_margin = 0 page_setup.left_margin = 0 page_setup.bottom_margin = 0 page_setup.right_margin = 0 if i != len(pages_stream) - 1: builder.insert_break(aw.BreakType.SECTION_BREAK_NEW_PAGE) save_options = aw.saving.PdfSaveOptions() save_options.cache_background_graphics = true builder.document.save("Output.html", save_options) def set_page_size(page_setup, width, height): page_setup.page_width = width; page_setup.page_height = height; Wir hosten unsere Python Pakete in PyPi- Repositorys. Bitte befolgen Sie die Schritt-für-Schritt-Anleitung zur Installation von "Aspose.Words for Python via .NET" in Ihrer Entwicklerumgebung.
Dieses Paket ist mit Python ≥3.5 und <3.12 kompatibel. Wenn Sie Software für Linux entwickeln, schauen Sie sich bitte die zusätzlichen Anforderungen für gcc und libpython in der Produktdokumentation an.
Sie können Dateien in vielen anderen Dateiformaten optimieren: